Free mag vol1 | Page 566

CHAPTER 14  BUILDING AND CONFIGURING CLASS LIBRARIES At this point in the game, there is no need to concern yourself with what the BinaryFormatter class is used for (you’ll examine this class in Chapter 20). For now, simply remember that the C# using keyword can be used to define aliases for lengthy fully qualified names or, more commonly, to resolve name clashes that can arise when importing multiple namespaces that define identically named types.  Note Be aware that overuse of C# aliases can result in a confusing code base. If other programmers on your team are unaware of your custom aliases, they could assume the aliases refer to types in the .NET base class libraries and become quite confused when they can’t find these tokens in the .NET 4.5 Framework SDK documentation! Creating Nested Namespaces When organizing your types, you are free to define namespaces within other namespaces. The .NET base class libraries do so in numerous places to provide deeper levels of type organization. For example, the IO namespace is nested within System, to yield System.IO. If you want to create a root namespace containing the existing My3DShapes namespace, you can update your code as follows: // Nesting a namespace. namespace Chapter14 { namespace My3DShapes { // 3D Circle class. public class Circle{ } // 3D Hexagon class. public class Hexagon{ } } } // 3D Square class. public class Square{ } In many cases, the role of a root namespace is simply to provide a further level of scope and, therefore, it may not define any types directly within its scope (as in the case of the Chapter14 namespace). If this is the case, a nested namespace can be defined using the following compact form: // Nesting a namespace (take two). namespace Chapter14.My3DShapes { // 3D Circle class. public class Circle{ } // 3D Hexagon class. public class Hexagon{ } 508