#525 – Namespaces Can Be Nested
February 23, 2012 2 Comments
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 DogLogger class whose full name is then DogLibrary.Utility.DogLogger.
namespace DogLibrary { public class Dog { } namespace Utility { public class DogLogger { } } }
Pingback: #527 – Defining a Nested Namespace Using Dot Notation « 2,000 Things You Should Know About C#
Pingback: #711 – The Global Namespace « 2,000 Things You Should Know About C#