User:CodingBot02/C Sharp Tutorial/Variables

Variables Programs typically use data to perform tasks. Creating a variable reserves a memory location, or a space in memory, for storing values. It is called variable because the information stored in that location can be changed when the program is running. To use a variable, it must first be declared by specifying the name and data type. A variable name, also called an identifier, can contain letters, numbers and the underscore character (_) and must start with a letter or underscore. Although the name of a variable can be any set of letters and numbers, the best identifier is descriptive of the data it will contain. This is very important in order to create clear, understandable and readable code! For example, firstName and lastName are good descriptive variable names, while abc and xyz are not. Variable Types A data type defines the information that can be stored in a variable, the size of needed memory and the operations that can be performed with the variable. For example, to store an integer value (a whole number) in a variable, use the  keyword: The code above declares a variable named myAge of type  integer . A line of code that completes an action is called a statement. Each statement in C# must end with a semicolon. You can assign the value of a variable when you declare it: or later in your code: Remember that you need to declare the variable before using it. Built-in Data Types There are a number of built-in data types in C#. The most common are: - integer. - floating point number. - double -precision version of float. - a single character. - Boolean that can have only one of two values: True or False. - a sequence of characters. The statements below use C# data types: Note that  char  values are assigned using single quotes and  string  values require double quotes. You will learn how to perform different operations with variables in the upcoming lessons!