Namespaces Can Be Nested

You can define a namespace at the top-level of a source file or you can define a namespace within another namespace.  When you define a namespace within another namespace, you can refer to the inner namespace using a dotted (outer.inner) syntax.
In the example below, we have a Dog class defined within the top-level DogLibrary namespace.  The full name for this type is DogLibrary.Dog.  We also define a Utility namespace within the DogLibrary namespace, and a DogLoggerclass whose full name is then DogLibrary.Utility.DogLogger.


1
2
3
4
5
6
7
8
9
10
11
12
13
namespace DogLibrary
{
    public class Dog
    {
    }
 
    namespace Utility
    {
        public class DogLogger
        {
        }
    }
}