命名空间的例子:

 namespace MyApplication
 {
     // The content to reside in the MyApplication namespace is placed here.
 }

命名空间的使用:

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

This will call the WriteLine method that is a member of the Console class within the System namespace.

using关键字将引入命名空间中的所有名字。

 using System;
 
 namespace MyApplication
 {
   class MyClass
   {
     void ShowGreeting()
     {
         Console.WriteLine("Hello, World!"); // note how System is now not required
     }
   }
 }

命名空间是全局的。两个源文件中的同一个命名空间将被编译器合并。

嵌套命名空间 编辑

 namespace CodeWorks
 {
     namespace MyApplication
     {
         // Do stuff
     }
 }

或者:

 namespace CodeWorks.MyApplication
 {
     // Do stuff
 }