Namespaces and Compilation Units

Listing 15.2 shows the most important code fragments for defining two namespaces called ElevatorSimulation (spanning lines 3–61 and containing the Elevator, Person, and Building classes) and BankSimulation (in lines 63–101 and containing the Account, Bank, and Building classes). The two namespaces are positioned beside each other in the same compilation unit. The class MyGlobalNamespaceClass (lines 103–120) has been thrown in to demonstrate a class that exists beside two namespaces and outside any namespace. The latter fact, as discussed in the previous section, causes it to belong to the global nameless namespace.

Listing 15.2. Two Namespaces Written Beside Each Other in a Compilation Unit
 001: using System; ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.