NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

namespace

The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally-unique types.

namespace name[.name1] ...] {
type declarations
}

where:

name, name1
A namespace name can be any legal identifier. A namespace name can contain periods.
type declarations
Within a namespace, you can declare one or more of the following types:

Remarks

Even if you do not explicitly declare one, a default namespace is created. This unnamed namespace, sometimes called the global namespace, is present in every file. Any identifier in the global namespace is available for use in a named namespace.

Namespaces implicitly have public access and this is not modifiable.

Section 3.6 and chapter 9 of the language reference discuss namespaces in more detail.

See 7.3 Member lookup for information about how the compiler resolves names.

See Access Modifiers for a discussion on the access modifiers that you can assign to elements within a namespace.

It is possible to define a namespace in two or more declarations. For example the following sample defines both classes as part of namespace MyCompany.

namespace MyCompany.Proj1 {
   class MyClass {
   }
}

namespace MyCompany.Proj1 {
   class MyClass1 {
   }
}

Example

using System;
namespace SomeNameSpace {
   public class MyClass {
      public static void Main() {
         Nested.NestedNameSpaceClass.SayHello();
      }
   }
   namespace Nested {   // a nested namespace
      public class NestedNameSpaceClass {
         public static void SayHello() {
            Console.WriteLine("Hello");
         }
      }
   }   
}

Output

Hello

See Also

C# Keywords | Grammar