In this lecture, you'll learn about the very useful string datatype. A string is just a sequence of Unicode characters that char datatype that we learned about last time. String is a reference type, not a value type. Our strings are objects. Let's go and take a look at some code that uses the string datatype. We'll do a number of things to demonstrate the string basics in this code. I'll prompt for and read in a gamertag. I'll prompt for and read in a high score. I'll extract the first character of the gamertag, and I'll print out each of those values. Let's start by prompting for and reading in the gamertag. We know how to prompt for things. We use console right. I'll just say enter gamertag. We're going to store the gamertag that the user enters into a variable. That variable will be of type string. I'll call a gamertag. We actually know from our past work that Console.ReadLine returns a string. In the past, we either parsed this string into a value type, like an int or a float. Or, as we saw in the previous lecture, we did some processing on the string and then extracted the first character in the string. But here we want the entire string. We're going to take the string that's returned by the Console.ReadLine method and we're going to put it into our gamertag variable. Let's come down here and print that value out. We might as well test this functionality before we move on to the next thing we're going to do. I'll print out gamertag an I'll print out the value of that variable. I'm going to want a space between the input and output portions of my code. I've added a Console.WriteLine there, as we've seen before when we did Console.WriteLine. But I went to remind you, I can take a string literal and I can use plus to combine it with some other string. In the past, we've been combining it with numbers, for example. But the big idea is we can take two strings and we can combine them using plus, which is called concatenation. We can concatenate two strings together, which is really just smashing them right next to each other to create a string that we use to pass in as an argument to the Console.WriteLine method. When I run the code, I'll enter my official gamertag. As you can see it printed out the same gamertag. That's how we can just take the string returned by the Console.ReadLine method and put it into a string variable. Next, we're going to prompt for and read in a high score. You'll notice by the way that in my prompts, I'm not being polite at all. I am never saying please. It turns out that adding please to prompts in software really just give an extra word that users have to blast by as they tried to figure out what you really want them to provide. This is our excuse to not be polite. Don't put pleases into your prompts, they're unnecessary in software. We've seen this before. We're going to store the user input into a numeric datatype, in this case an integer. We need to parse the results of calling the Console.ReadLine method into the appropriate datatype. We know the Console.ReadLine method returns a string and then we parse it into an int and store that into our high score variable. We didn't really talk about this previously because we hadn't talked about strings yet, but you can't do a typecast. As we can see, the compiler error message tells us we can't convert type string to int, so we can't do a typecast. We can't do a typecast because a string is a sequence of characters. For each 16-bit chunk of the string, we have ones and zeros that are a Unicode representation of a character. Trying to typecast each of those 16-bit chunks of Unicode representations into the ones and zeros that actually represent an integer is not something that we can just automatically do. We have to do more work than that. The more work that we have to do is int.Parse. Now, it's nice for us that somebody wrote the int.Parse method so we don't have to write it. But I'll tell you, you could write it. After we finish talking about extracting characters from the string, you could actually write a method that parses a string into an integer. All you'd have to do is walk the string and process each character and use an if statement to convert that character into a number. Then as you moved along the stream, you'd of course have to multiply by 10 each time because you're moving through the places in the number. But you could absolutely write a method that does what the int.Parse method does knowing what you know about loops and Math, and accessing specific characters industry. We won't do that though. We'll just print out the highest score. My gamertag again, and this time I have a high score. As you can see, it prints out both of those values properly. The last thing we'll do is extract the first character of the gamertag, which we actually saw in the previous lecture. We weren't extracting the first character of the gamertag. We were extracting a menu choice, but the idea is the same. First gamertag character is equal to our gamertag string. Of course we can't do this, because gamertag is a sequence of characters and first gamertag character is a single character. We're getting an error message that we can't implicitly convert type string to a char and we already know that. But we also know that we can index into our sequence of characters by using our square bracket notation, putting an index between those square brackets. We'll print this out as well. When I run the code, I'll make my gamertag abc. I have a horrible high score. As you can see, I've extracted the first gamertag character properly as well. Much of this we've seen before in our previous work, either recently in the previous lecture or in previous modules end or previous courses. But the big ideas are, we can use Console.ReadLine to get a string and put it right into a string variable. We can take the string returned by the Console.ReadLine method and parse it into a value type, and we can extract a particular character from a string and put it into a char variable. Those are the foundational ideas behind strings. To recap, in this lecture you learned how to use the string datatype. You learned that strings are a sequence of Unicode characters. You learned that strings are really useful for getting and processing user input. You learned that string is a reference type, not a value type in C-sharp. One more thing you should know, strings are immutable. Immutable means once we create a string, we can't change it. We can't remove characters and we can't add characters. If we need to do that with a string, we actually use a different class called the StringBuilder, but you should understand that if we're using the basic string datatype, the string objects that we create are immutable. We can't change them once we create that string object.