Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata