Declaring Variables


C# follows a similar scheme of variable declaration to Java, where the declaration consists of a datatype keyword and followed by the name of the variable to hold that datatype. For example, to declare an integer (int) variable called myInt, you would use the following code:

 int myInt; 

Identifiers are the names you give to classes, objects, class members, and variables. Raw keywords, discussed in the next section, can neither be Java nor C# identifiers; however, in C# you can use keywords as variable names by prefixing the name with @. Note that this exception is only with keywords and does not allow the breaking of any other rules. Although identifiers may have letters and numbers, the first letter of the identifier in both C# and Java must not be a number. Here are some valid and invalid examples of variable declaration:

 int 7x; //invalid, number cannot start identifier int x7; //valid, number may be part of identifier int x; //valid int x$; //invalid, no symbols allowed int @class; //valid, prefix @ allows it to be used as an identifier int @7k; //invalid, prefix @ only works for keywords 




Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net