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 ...
Get C# 5.0 Programmer's Reference 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.