| title | Namespaces (C# Programming Guide) | ||
|---|---|---|---|
| ms.date | 07/20/2015 | ||
| ms.prod | .net | ||
| ms.technology |
|
||
| ms.topic | article | ||
| helpviewer_keywords |
|
||
| ms.assetid | b1c4ab46-3fad-4ffa-9deb-dd50a2d8c65a | ||
| caps.latest.revision | 27 | ||
| author | BillWagner | ||
| ms.author | wiwagn |
Namespaces are heavily used in C# programming in two ways. First, the .NET Framework uses namespaces to organize its many classes, as follows:
[!code-csharpcsProgGuide#22]
System is a namespace and Console is a class in that namespace. The using keyword can be used so that the complete name is not required, as in the following example:
[!code-csharpcsProgGuide#1]
[!code-csharpcsProgGuide#25]
For more information, see using Directive.
Second, declaring your own namespaces can help you control the scope of class and method names in larger programming projects. Use the namespace keyword to declare a namespace, as in the following example:
[!code-csharpcsProgGuideNamespaces#6]
Namespaces have the following properties:
-
They organize large code projects.
-
They are delimited by using the
.operator. -
The
using directiveobviates the requirement to specify the name of the namespace for every class. -
The
globalnamespace is the "root" namespace:global::Systemwill always refer to the .NET Framework namespaceSystem.
See the following topics for more information about namespaces:
[!INCLUDECSharplangspec]
C# Programming Guide
Namespace Keywords
using Directive
:: Operator
. Operator