Namespaces (C# Programming Guide)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Namespaces are heavily used in C# programming in two ways. First, the .NET Framework uses namespaces to organize its many classes, as follows:

        System.Console.WriteLine("Hello World!");

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:

using System;


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:

    namespace SampleNamespace
        class SampleClass
            public void SampleMethod()
                  "SampleMethod inside SampleNamespace");

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.

See the following topics for more information about namespaces:

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

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