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

    申明

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

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

  • 相关阅读:
    Python3报错处理:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
    Python/Shell/MySQL时间获取与格式转换
    MySQL客户端不需要commit代码需要commit原因分析
    Python3多线程及线程池实现教程
    人工智能、机器学习及深度学习的区别与联系
    GitHub基本使用操作
    Python3 UNIX domain sockets使用代码实现
    Linux core dump文件生成与使用
    Linux setuid使用
    Shell脚本调试操作
  • 原文地址:https://www.cnblogs.com/Athrun/p/1277284.html
Copyright © 2020-2023  润新知