2.3. Variables and Data Types

As with all programming languages, you keep track of data in C# using variables. Variables can store numbers, text, dates, and times, and they can even point to full-fledged objects.

When you declare a variable, you give it a name, and you specify the type of data it will store. To declare a local variable, you start the line with the data type, followed by the name you want to use. A final semicolon ends the statement:

// Declare an integer variable named errorCode.
int errorCode;

// Declare a string variable named myName.
string myName;


Remember, in C# the variables name and Name aren't equivalent! To confuse matters even more, C# programmers sometimes use this fact to their advantage—by using multiple variables ...

Get Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.