Naming Conventions in C#

 

Identifiers are used  to describe allocated memory types such as integer, doubles, strings, longs, classes.....etc defined by C# or developer. Generally we have to follow the below rules while creating the identifiers and those rules are  

 

·         Identifiers can start with any Unicode letter or an underscore. 

·         Identifiers are case-sensitive. 

·         Identifiers must be unique within  a particular scope like namespace, class, method or code block. 

 

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. 

 

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 VB 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.

 

There are two recommended naming conventions for C# most of the developers follows,

 

Pascal casing: This convention capitalizes the first character of each word ,as in int EmpId. Pascal casing is the default convention for all names with the exception of protected instance fields and parameters.

 

Camel casing: This convention capitalizes the first character of each word except the first word, as in int empId. This is used only for protected instance fields and parameters.

 

You can find example for Pascal casing and Camel casing below.

 

namespace ConsoleApplication1 

{ 

    class Program 

    { 

        static void Main(string[] args) 

        { 

            int EmpId = 100; //Pascal casing 

            int  empId = 100; //Camel casing 

        } 

    } 

}

 

Generally to declare the variables in C# we follow the Camel casing and for methods,  functions we use Pascal casing in C#.