Declare A Variable

You can structure the way you store information with variables. When you declare variables, you set up locations in memory where your program can store the many values it needs to perform its task. Defining a variable enables you to assign an easy-to-remember name to a memory location.

In the real world, you deal with many classifications of information. This information could be a date, money, a person's name, or an age. When you build applications that use this information, you will need to temporarily store these values for later use in the application.

Using variables in C# requires declaration and initialization. Declaration tells the application how to allocate memory for the information you want to store. This is the first step in using variables and is required before you perform the initialization. Initialization is setting an initial value for the variable.

To declare a variable in C#, you will need to determine what type of information you want to store. The type of information you are storing will determine what the proper data type to use is. If you are storing someone's first name, you can use the string data type for its storage. If you are storing someone's age, you can use one of the integer data types.

DECLARE A VARIABLE

DECLARE A VARIABLE

D Open your text editor.

-H Between the curly braces, type static void Main() and press Enter to create the Main function.

Q Type { }, placing the opening and closing curly braces on separate lines.

D Open your text editor.

—0 Type using System; to import the System namespace and press Enter.

< Type the name of the class you want to create and press Enter.

—Q Type { }, placing the opening and closing curly braces on separate lines, to specify the body of the class.

-H Between the curly braces, type static void Main() and press Enter to create the Main function.

Q Type { }, placing the opening and closing curly braces on separate lines.

Was this article helpful?

0 0

Post a comment