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");
            }
        }
    }
}
 

申明

非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

博文欢迎转载,但请给出原文连接。

原文地址:https://www.cnblogs.com/Athrun/p/1277284.html