1.5 Creating Valid Identifier Names

 <  Day Day Up  >  

1.5 Creating Valid Identifier Names

You want to ensure that the identifier follows the rules of valid identifier naming.


Technique

Your identifier cannot be the same as that of a C# keyword. You are free to use any combination of letters , numbers , and underscore characters as long as the identifier does not start with a number. Furthermore, you can use the @ symbol as the first character in your identifier. Listing 1.3 shows several valid and invalid identifier names.

Listing 1.3 Demonstrating Valid and Invalid Identifier Names
 namespace _5_Identifiers {     class Class1     {         [STAThread]         static void Main(string[] args)         {             int i;          // valid             int @int;       // valid but confusing             int INT;        // valid since C# is case sensitive             int 4_Score;    // Not valid. Cannot begin with a digit             int in@t;       // not valid. @ symbol not at beginning             int int;        // not valid. Cannot use keywords         }     } } 

Comments

Identifiers name certain programming elements within a program. They include such items as namespace names, classes, and variables . It is good programming practice to create identifiers that convey important information about the element it is defined as. In the days before .NET, Hungarian notation was used as the de facto standard for identifier naming, at least for those using the C++ language within a Windows program. Although some people argue for or against its suitability as a standard, the fact remains that it was a standard which could alleviate some of the issues that go along with reading someone else's source code. With the release of .NET, Microsoft dropped the Hungarian-notation guideline due to the cross-language support within the .NET Framework. Some of these identifier guidelines include using a combination of Pascal and Camel case for character capitalization within an identifier as well as using semantics in the identifier name. If you want to learn more about the guidelines Microsoft uses for the .NET Framework, search MSDN using the phrase "naming guidelines."

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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