CHAPTER 19

image

Namespaces

Namespaces provide a way to group related top-level members into a hierarchy. They are also used to avoid naming conflicts. A top-level member, such as a class, that is not included in a namespace is said to belong to the default namespace. It can be moved to another namespace by being enclosed in a namespace block. The naming convention for namespaces is the same as for classes, with each word initially capitalized.

namespace MyNamespace{   class MyClass {}} 

Nested namespaces

Namespaces can be nested any number of levels deep to further define the namespace hierarchy.

namespace MyNamespace{   namespace NestedNamespace ...

Get C# Quick Syntax Reference 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.