C# Coding Conventions (C# Programming Guide)
C# Coding Conventions (C# Programming Guide):
Below are our C# coding standards, naming conventions, and best practices.
Use these in your own projects and/or adjust these to your own needs.
The C# Language Specification does not define a coding standard. However, the guidelines in this topic are used by Microsoft to develop samples and documentation.
Coding conventions serve the following purposes:
- They create a consistent look to the code, so that readers can focus on content, not layout.
- They enable readers to understand the code more quickly by making assumptions based on previous experience.
- They facilitate copying, changing, and maintaining the code.
- They demonstrate C# best practices.
Naming Conventions and Standards:
Pascal casing:
the first character of all words is upper
case and the other characters are lower case.
Camel casing:
the first character of all words, except the
first word, is upper case and other characters are lower case.
Use Pascal casing for class names:
public class HelloWorld
{
...
}
Use Pascal casing for method names:
public class HelloWorld
{
void SayHello(string
name)
{
...
}
}
Use Camel casing for variables and method parameters:
public class HelloWorld
{
int totalCount = 0;
void SayHello(string
name)
{
string fullMessage =
"Hello " + name;
...
}
}
Do not use Hungarian notation to name variables. In earlier
days, most programmers liked it: having the data type as a prefix for the
variable name and using m_ as the prefix for member variables, e.g:
string m_sName;
int nAge;
Comments
Post a Comment