The casing conventions for C# are shown in Table C.2
Category | Casing |
---|---|
Local variables | Camel casing |
Parameters passed into methods (considered local variables) | Camel casing |
All other identifiers (names of namespaces, classes, interfaces, all class members) | Pascal casing |
This implies that your method and field names should use Pascal casing, like your classes. In C#, camel casing should be reserved only for local variables. [2]
[2] This is very different from Java's naming conventions. Java advocates that all class and interface identifiers should use Pascal casing, and all other identifiers use camel casing. C# says that all identifiers should use Pascal casing, except for local variables which should use camel casing.
Table C.3 lists some common suffixes and prefixes that should be used in C#.
Category | Naming comments |
---|---|
Attributes | Suffix with Attribute |
Exceptions | Suffix with Exception |
Events | Suffix with Event |
Event arguments | Suffix with EventArgs |
Event handler delegate | Suffix with EventHandler |
Interfaces | Prefix with I |
Pointer variables | Prefix with p |
Hungarian notation is to be avoided, even for method parameters.
All upper case casing is to be avoided, even for constants. Use Pascal casing for constants. [3]
[3] I have noticed that some constants in sample C# codes in the MSDN documentation and VS.NEThelp files are being named using all upper case casing. However, it is clearly noted in the C# Language Specification itself about constants using the Pascal notation. As I have mentioned, conventions and guidelines are flexible, but I would recommend following the official language specification.
The only occasion when all upper case casing can be considered is when the whole name is an abbreviation. For example, instead of choosing Windows.Forms.UserInterface as a namespace, you can use Windows. Forms.UI since 'UI' is universally accepted as an abbreviation for user interface.
All other commonsense guidelines apply. For example, you should select meaningful names for identifiers and use abbreviations sparingly (or avoid them altogether). [4]
[4] Commonsense guidelines are not listed here because people without commonsense won't make developers.
18.118.12.50