O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

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

Chapter 13 Namespaces

What’s in This Chapter

  • Namespace collisions
  • The using directive
  • Project and item templates
  • Making and resolving namespaces
  • Default and global namespaces

Wrox.com Downloads for This Chapter

Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at www.wrox.com/go/csharp5programmersref on the Download Code tab.

In large applications, name collisions are fairly common. A developer working on a billing system might create a Customer class. Meanwhile another developer working on a customer complaint tracking system might define a different Customer class. Each class will have different properties, methods, and events that are useful for its application.

Having two classes with the same name like this won’t cause any problems until you try to integrate the two programs. At that point, the program won’t be able to tell which kind of Customer class to use under different circumstances.

This situation in which multiple items have the same name is called a namespace collision or namespace pollution.

Namespaces enable you to group code so that you can tell the program where to find a particular class. For example, the developer working on the billing system might use the Billing namespace and the developer working on the complaint tracking system might use the CustomerSatisfaction namespace.

Now when you glue code from the two programs together in one mega-program, you can refer to the ...

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