Naming Conventions In C#.Net

For any developer, Naming Convention is a best practice to work on any development project. Let’s discuss more about the naming convention in this article.

For any developer, Naming Conventions is a best practice when working on any development project. Let’s discuss more about  Naming Conventions in this article.

Why Naming Conventions?

Naming Conventions are very important to identify the usage and purpose of a class or a method and to identify the type of variable and arguments.

Types of Naming Conventions

Below are the two major parts of Naming Conventions.

  • Pascal Casing (PascalCasing)
  • Camel Casing (camelCasing)

Pascal Casing (PascalCasing)

Use PascalCasing for class names, method/function names, and constants or read-only variables. 

  1. //Use PascalCasing for Class Names  
  2. public class Products {  
  3.     //Use PascalCasing for Constant Variable or Read only Variables  
  4.     public  
  5.     const string ProductType = "General";  
  6.     //Use PascalCasing for Method Names  
  7.     public void GetProductDetails() {  
  8.         //Your logic here...  
  9.     }  
  10. }  

Camel Casing (camelCasing)

Use camelCasing for variable names and method arguments.

  1. public class Products {  
  2.     public  
  3.     const string ProductType = "General";  
  4.     //Use camelCasing for Method Arguments  
  5.     public void GetProduct(int productCategory) {  
  6.         //Use camelCasing for Variables Name  
  7.         int productCount;  
  8.         //Your logic here...  
  9.     }  

Below are the best practices to follow in your projects. Do not use Hungarian notation or any other type of identification. 

  1. //Use  
  2. string userName;  
  3. int counter;  
  4. //Avoid  
  5. string strUserName;  
  6. int iCounter; 

Prefix “I” letter for any Interface.

  1. public interface IProduct {  
  2.     //Interface logic here...  

Do not use underscores (_) in between words in variables.

  1. //Use  
  2. string userName;  
  3. string departmentName;  
  4. //Avoid  
  5. string user_Name;  
  6. string department_Name; 

Avoid using abbreviations for variable names.

  1. // Use  
  2. string departmentName;  
  3. string employeeName;  
  4. // Avoid  
  5. string deptName;  
  6. string empName; 

Use undersocre (_) as prefix for private static or global variables.

  1. public class Products {  
  2.     //User underscore for Private & Global Variables  
  3.     private static string _productGroup = "Packed";  
  4.     public List < Product > _products;  
  5.     public void GetProduct(int productCategory) {  
  6.         //Your logic here...  
  7.     }  

Hope this helps you with your projects.

Happy Coding.