Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

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# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata