Team LiB
Previous Section Next Section

Chapter 1: Common Type System

Identifiers and Naming Conventions

Identifiers are used to describe allocated memory types such as integer, longs, classes, and other types defined by C# or by you, as the developer. The rules for identifiers are simple:

Typically, identifiers should be descriptive and use whole words without abbreviations. Your identifiers, whether they are for types or methods, should describe the intent that you have in mind when you develop the type or method. The focus should be on the readability of the code.

Caution?/td>

Make sure that you do not create methods, fields, or properties that have the same identifiers that differ only in case. If you do this, languages that are not case-sensitive, such as Visual Basic, will have difficulties in using your code.

Your identifiers become the symbolic name that identifies the memory location of the given type when a declaration is made. If an identifier is used in the namespace/global part of the code, you cannot use it again throughout any scope within that namespace, including child parts.

In addition to identifier names, there is also the issue of naming conventions for identifiers. In C#, there is a defined set of naming conventions and recommendations. C++ programmers are familiar with Hungarian notation, which required that identifiers be prefixed with their type. Ironically, Hungarian notation is no longer a recommended naming convention. The following are the two recommended naming conventions for C#:

The following example shows the use of identifiers in C#.

Code Example: Identifiers and Naming Conventions
Start example
//Adds System namespace
using System;
//Defines a new namespace
namespace Client.Chapter_1___Common_Type_System
{
      //Defines a new class
      class MyMainClass
      {
            //Defines a static method that serves as an entry point
            //for the application
            static void Main(string[] args)
            {
                  //Declares an instance of variables
                  int MyInt = 12345;
                  long MyLong = MyInt;
                  short MyShort = (short)MyInt;
                  My2ndFunction(MyInt);
            }
            //Defines a public static method
            public static int My2ndFunction(int myInt)
            {
                  return myInt;
            }
      }
}
End example

Team LiB
Previous Section Next Section