Nested Namespaces

Apart from writing namespaces beside each other, as demonstrated in Listing 15.2, you can also nest namespaces inside other namespaces as mentioned earlier. The following scenario provides an example of a typical situation where namespace nesting would be convenient.

Suppose the editors at Sams Publishing wanted to provide a convenient way for programmers to reuse the code written in several of their C# books, including this one. An overall namespace hierarchy for doing this could look like that shown in Listing 15.3. An outermost namespace called Sams contains namespaces beside each other, named after each of Sams C# books (for brevity sake, only the two namespaces CSharpPrimerPlus and SamsTeachYourselfCSharpIn21Days have been ...

Get C# Primer Plus 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.