Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 2.88 KB

File metadata and controls

61 lines (43 loc) · 2.88 KB
title Namespaces (C# Programming Guide)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
helpviewer_keywords
C# language, namespaces
namespaces [C#]
ms.assetid b1c4ab46-3fad-4ffa-9deb-dd50a2d8c65a
caps.latest.revision 27
author BillWagner
ms.author wiwagn

Namespaces (C# Programming Guide)

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 Overview

Namespaces have the following properties:

  • They organize large code projects.

  • They are delimited by using the . operator.

  • The using directive obviates the requirement to specify the name of the namespace for every class.

  • The global namespace is the "root" namespace: global::System will always refer to the .NET Framework namespace System.

Related Sections

See the following topics for more information about namespaces:

C# Language Specification

[!INCLUDECSharplangspec]

See Also

C# Programming Guide
Namespace Keywords
using Directive
:: Operator
. Operator