Naming Conventions and Styles
Use Pascal casing for type and method names and constants:
public class SomeClass { const int DefaultSize = 100; public SomeMethod() {} }
Use camel casing for local variable names and method arguments:
int number; void MyMethod(int someNumber) {}
Prefix interface names with
I
:interface IMyInterface {..}
Prefix private member variables with
m_
.Suffix custom attribute classes with
Attribute
.Suffix custom exception classes with
Exception
.Name methods using verb/object pairs, such as
ShowDialog()
.Methods with return values should have names describing the values returned, such as
GetObjectState()
.Use descriptive variable names.
Avoid single-character variable names, such as
i
ort
. Useindex
ortemp
instead.Avoid using Hungarian notation for public or protected members.
Avoid abbreviating words (such as
num
instead ofnumber
).
Always use C# predefined types, rather than the aliases in the
System
namespace. For example:object NOT Object string NOT String intNOT Int32
With generics, use capital letters for types. Reserve suffixing
Type
for when dealing with the .NET typeType
://Correct: public class LinkedList<K,T> {...} //Avoid: public class LinkedList<KeyType,DataType> {...}
Use meaningful namespace names, such as the product name or the company name.
Avoid fully qualified type names. Use the
using
statement instead.Avoid putting a
using
statement inside a namespace.Group all framework namespaces together and put custom or third-party namespaces underneath:
using System; ...
Get Programming .NET Components, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.