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;

NOTE

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.