Mechanics

Mechanics, in this case, refers to the process of selecting a name for a given metadata token in the language such as class, interface, field, parameter, and so on.

Microsoft, in its “Naming Guidelines” topic (under the “.NET Framework Design Guidelines” in the .NET SDK Documentation), contains a list of “Do’s” and “Don’ts” regarding naming guidelines. Rather than reprint that list here in either parroted or paraphrased form, we just make the following general suggestions.

Names should be descriptive and concise. More importantly, they should be meaningful to the principal consumers of the name—use syntax, phraseology, and terms that are familiar to the developers who will use the code you are writing.

As suggested, since classes and interfaces and value types are often marked “public,” use Pascal-case for their names.

Interfaces should always be prefixed with I, following in COM tradition. Following the Pascal-casing rules, make sure the next letter of the interface is also capitalized, as in IComparable (indicating an interface that provides comparable behavior). Frequently, interfaces are also descriptive names (Comparable, Disposable, and so on), rather than nouns.

Other than the I for interfaces, do not use any sort of prefixes on names. This is what namespaces are for.

Attributes should always end in the Attribute suffix. The C# compiler can use shorthand naming rules (allowing you to leave off the Attribute portion of the name when using the attribute) if you follow ...

Get C# in a Nutshell, Second 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.