Do use concise & meaningful English words. Do favor readability over brevity.
// correct
string fullName = GetFullName() {};
// avoid
string x = GetFullName();
Do use recommended notations for certain object
| Object Name | Notation |
|---|---|
| Class name | PascalCase |
| Interface name | IPascalCase |
| Constructor name | PascalCase |
| Method name | PascalCase |
| Method argument | camelCase |
| Local variable | _camelCase |
| Constant name | PascalCase |
| Property name | PascalCase |
| Enum type name | PascalCase |
| Delegate name | PascalCase |
Do NOT use Hungarian notation
// correct
var name;
// avoid
var strName;
Do NOT use SCREAMING CAPS for constants or readonly variables
// correct
const string DefaultCurrency = "USD";
// avoid
const string DEFAULTCURRENCY = "USD";
Do NOT use abbreviation, unless it’s a commonly used abbreviation
// correct
var user;
Guid EmployeeId { get; set; }
void ParseXml();
// avoid
var usr;
Guid EmpId {get; set;}
bool ValidatePswrd(string usr, string pswrd);
Do concate words without underscore (
_) or hypen (-) separator
// correct
var fullName;
var isUserRegistered;
// avoid
var full_name;
var is-user-registered;
Do organize namespace and class name to match their directory structure
// located in ~/Project/Client.cs
namespace Company.Website.Project
{
class Client
{
}
}
Do use
usingdirective to define namespaces whenever possible. Avoid writing fully quilify name if it is too long
// correct
using