C#語法學習二(NameSpace)

//命名空間的使用
//.NET Framework類庫由命名空間組成.每個命名空間都包含在程序中使用的類型:類,結構,枚舉,委托和接口.
using System;
namespace Athrun
{
  
class test
  {
      
static void Main()
      {
          A.PrintName a
=new A.PrintName();
          a.intro();
          B.PrintName b
=new B.PrintName();
          b.intro();
      }
  }
}
namespace A
{
    
public class PrintName
    {
        
public void intro()
        {
            Console.WriteLine(
"My name is A");
        }
    }
}
namespace B
{
    
public class PrintName
    {
        
public void intro()
        {
            Console.WriteLine(
"My name is B");
        }
    }
}

 

 


/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2008/8/26
 * Time: 下午 06:56
 * 命名空間可以嵌套也可以用別名來取代
 * 有時間會因為命名空間過長,用起來不是很方便,所以建議用別名.
 * 下面有一個比較怪的例子別名可以直接用來代替到類名.k=A.A1.PrintName;
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 
*/

using System;
using k=A.A1.PrintName;
using m=A.A2;
namespace Athrun
{
  
class test
  {
      
static void Main()
      {
          k a
=new k();
          a.intro();
          m.PrintName b
=new m.PrintName();
          b.intro();
      }
  }
}
namespace A
{
    
namespace A1
    {
        
public class PrintName
        {
            
public void intro()
            {
                Console.WriteLine(
"My name is A1");
            }
        }
    }
    
namespace A2
    {
        
public class PrintName
        {
            
public void intro()
            {
                Console.WriteLine(
"My name is A2");
            }
        }
    }
}
 
posted @ 2008-08-27 09:01  Athrun  阅读(291)  评论(0编辑  收藏  举报