Let's continue our Quick start and C-sharp by talking more in depth about variables, you can think of a variable as a little box that holds some information in the computer's memory, such as the number 25. You could then reference that information by a variable name, such as player health. So in this example, player health would equal 25, which perhaps is the amount of health points the player has left. During the game, the player may gain or lose health points. In code, we would use the player health variable to get or set the current player's health. Here are the C sharp rules for naming things like variables names and classes. Names cannot contain spaces. They must begin with a letter. They can contain letters, numbers and the underscore character. They are case sensitive. So what letters are capitalized matters and ideally, names should be descriptive, so the code is more human readable. When you create a variable, you give it a name. Variable names follow the rules that we just laid out for any identifier. For variable names, I like to use what is called lower camel casing. Where you lower case the first word of the variable name. And if you use multiple words within a name, you capitalize the first letter of each subsequent word, to create logical, easy-to-understand names. Such as player health shown here. When you create a variable, you also give it a data type. The type defines what type of information the variable stores. common types are integers are whole numbers, such as negative 1012 and three. Floating Point numbers that have a decimal place such as negative 1.45, 0.0, and 45.3 in C# we add an f after the floating point number to clarify that it's a floating point number. Boolean's that are set to true or false, and strings that store a combination of characters. Other data types that you encounter a lot in unity are vector twos that store an X and Y position and vector threes that store an X, Y, and Z position. Another common data type is a game object that stores a reference to a game object or prefab. There are data types for any component. For example, an audio source type would be used to store a reference to an audio source component. We'll talk more about this later. You can also optionally set the access modifier of the variable to things such as public or private. Depending on how widely you want the variable to be accessible. For example, a private variable is just available within the current scope of the code such as within a class or function. A public variable is a variable outside the current scope. Understanding the scope of code is something that you will pick up on over time. If you don't set the access modifier, generally the variable is assumed to be a private variable. C# is a strongly type language which means that you must define the data type of the variable such as string, integer, Boolean, or float. You can assign the variables using the equal sign to literals as shown in the top four lines. Or you can assign variables to the results of a function as shown in line six. The variables we've been talking about so far are primitive. Datatypes that is they hold a single data value such as an integer float Boolean or string. You can also create variables that are compound types that holds multiple data values. In C sharp Arrays and Lists are compound data types that you can use. Arrays are great for storing predefined lists of related information. For example, if you want to store a list of family names, you could do so in an array. Here's an example block of code that creates an array. In the first line of code, we define a new variable. The data type is a string, but by putting the two brackets after the datatype, we're saying that we want an array of strings. The variable name is family. We then set the variable to a new array of strings with a size of 5. This creates the array in memory. In line two, we've referenced the first index position of the array variable using the two brackets with the index number of zero, and then we set it to the string holmer. Notice that the array starts at element zero, not one. We say arrays are zero based, since they start at index position zero. In the rest of the lines, we set the remaining four elements of the array to the rest of the family members. There actually is a shorthand way to create this array, as shown here. In one step, we define the array and pre populate it with the names. In this example block of code, we use the shorthand method to set up the array of strings in line one. In line two and three, we output two of the array elements to the console, index element zero, which is Homer and index element two, which is Bart. Lastly, we output the total family size. We can get the length of an array using the length property of the array element as shown. There are several other properties and methods available to work with arrays. Lists are similar to arrays, but work a little different. In this block of code, I start by creating a list variable. The syntax is a bit different than arrays. I specify that I want to list and then I put the data type. In this case string, between the less than and greater than sign. I then set the variable name to family and set it equal to a new list of type string. Notice, we do not need to find the size of a list like we did for an array. A list can grow and shrink over time. In line two to six, I add elements to the list using the Add method. In line eight and nine, I get elements of the list in the same method as we did with arrays by specifying the index into the list between two brackets. And to get the size of the list, I use the count property, which is similar to the length property of an array. Just like arrays, there are several other properties and methods available to work with lists. Given that C sharp is a strongly typed language, you cannot change the data type implicitly, you must do so by converting the data. So if you have a string that holds a whole number, you must convert it to an integer before doing addition and storing it into an integer variable as shown here. The result of this would be 44 output into the console. If you have a string that holds a decimal number, you must convert it to a float before doing addition and storing it in a float variable as shown here. The result of this would be 13.1 outputted to the console. And if you have an integer that you want to add to a string, you should convert it to a string before concatenating the string to the number as shown here. The result of this would be score 100 output into the console. So you also sometimes need to change between number types. So if you have an integer that you want to add to a float, you need to cast the integer to a float as shown here. The result of this would be 15.4 output into the console. And if you want to go the other direction, that is you want to convert a float to an integer. You need to cast the float to an integer as shown here. The result of this would be 25 outputted to the console, since casting the float to an integer will effectively drop the decimal place. One thing computers are good at is manipulating data. When it comes to numbers. That means basic math. For example, we can do integer math with plus minus divide and times. This example would result in 16 being outputted to the console window. Here is a similar example of floating point math. This would result in 13.8, being outputted to the console window. Note that C sharp follows the standard order of precedence. We all learned in math class where the innermost parentheses are calculated first, then multiplication and division, and then addition and subtraction within the current level of parentheses. So in the first example, the computer will do the calculation in the parentheses first five minus three, which equals two. Then multiply that by 12, which equals 24, which is stored in the variable x, then y equals x divided by two, or 24 divided by two, which equals 12. And then add four to equal 16. Of course the computer does all this for us, so we don't need to calculate it in our heads. And notice the difference between integer math and floating point math, particularly when it comes to division. There are a number of common math operations that you tend to do a lot in C sharp. There is a shortcut notation that you can use to perform these operations. So if you want to add the number one to a variable, you can use plus plus, or you can use minus minus to subtract one. You can also use plus equal to add one variable to another and store the result back into the first variable or minus equal to subtract one variable from another and store the result in the first. Strings are another data type that we often want to manipulate in some way. We've already seen the use of plus to add two strings together. However, we generally call this concatenation rather than adding when talking about strings. Here's an example where we have two string variables that we concatenate together with a space between. The output in this case would be my name in the console window. Strings like all data types are based on a class. When we create a variable, we're instantiating an object based on the class. So when I create a string variable, I'm making an object based on the string class. Therefore, the string variable has properties and methods, just like other objects. If you look up the documentation on the string class, you'll learn what properties and methods are available. One common use string property is length to get the length of the string. In this example, I'll put in the length of the string contained in the variable to the console window. In this case, the output would be five. Since there are five characters in Brian, of course, we can output something a bit more user friendly, as shown here, where the output would be two strings concatenated together with the length. In this case, it would say the string is five characters long. There are several methods available to work with strings. For example, there is To Upper and To Lower methods which convert the string into either or all uppercase or all lower case letters. There is a Trim method that trims off any white space at the beginning or ending of a string, as shown here. There is also a trim start or trim in method if you want to trim off just one side or the other. And there's a replace method for replacing a substring within the string with something new. In this example I'm replacing br with j i ll to make Jillian. These are just a few of the several String class methods. With visual studio, there is a feature called intellisence, which provides you with just in time documentation as you program. For example, here I just typed a period after the variable name and the menu popped up with all the possible properties, and methods for this variable. Given that it was of type string, and here when I rolled my mouse pointer over replace, that popped up a tooltip to describe what the replace method does and how it works. This feature really helps both beginner and experienced programmers alike. [MUSIC]