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 Naming convention in this article.
Why Naming Conventions?
Naming Convention is very important to identify usage and purpose of class or method and to identify 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.
//Use PascalCasing for Class Names public class Products { //Use PascalCasing for Constant Variable or Read only Variables public const string ProductType="General"; //Use PascalCasing for Method Names public void GetProductDetails() { //Your logic here... } }
Camel Casing (camelCasing): use camelCasing for variables names and method arguments.
public class Products { public const string ProductType="General"; //Use camelCasing for Method Arguments public void GetProduct(int productCategory) { //Use camelCasing for Variables Name int productCount; //Your logic here... } }
Below are the best practices to follow in your projects:
Do not use Hungarian notation or any other type identification.
//Use string userName; int counter; //Avoid string strUserName; int iCounter;
Prefix “I” letter for any Interface.
public interface IProduct { //Interface logic here... }
Do not use underscores (_) in between words in variables.
//Use string userName; string departmentName; //Avoid string user_Name; string department_Name;
Avoid using abbreviation for variables name.
// Use string departmentName; string employeeName; // Avoid string deptName; string empName;
Use undersocre (_) as prefix for private static or global variables.
public class Products { //User underscore for Private & Global Variables private static string _productGroup="Packed"; public List<Product> _products; public void GetProduct(int productCategory) { //Your logic here... } }
Hope this helps you in your projects.
Happy Coding 🙂