O'Reilly logo

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

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Namespaces

The general pattern to follow when naming namespaces is:

CompanyName.TechnologyName

Some examples of well-formed namespaces are:

Microsoft.Office
Corel.OfficePerfect 
OReilly.CSharpInANutshell

One problem that may arise, particularly as more companies begin to write code for the .NET platform, is that the “company-level” namespaces may clash. Java sought to avoid this problem by strongly suggesting companies use their reverse-DNS name (“oreilly.com” produces “com.oreilly” top-level namespace names), since DNS names are guaranteed to be unique. Over time, however, this proved to be less of an issue than originally thought, and many companies began to use the “center” name in the DNS name (for instance “oreilly” in “oreilly.com”). There is no reason to believe this convention won’t continue to work in .NET.

For legibility, use Pascal case, and separate logical components with periods (for example, Microsoft.Office.PowerPoint). However, if your product involves nontraditional capitalization, it’s okay to use that system, even if it deviates from normal namespace casing (for example NeXT.WebObjects, OReilly.Network and ee.cummings).

Plural namespace names are recommended where appropriate — for example, use System.Collections, not System.Collection. Exceptions to this rule are brand names and abbreviations — for example, use System.IO not System.IOs.

Never reuse names across namespace and class names — for example, the System.Debug namespace should never have a class named Debug ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required