C#.NET中的部分类定义(关键字partial)

/*
 * Created by SharpDevelop.
 * User: noo
 * Date: 2009-8-16
 * Time: 17:54
 * 
 * 部分类定义(关键字partial)
 * 
 * 部分类定义,简言之,就是使用部分类定义,使类的定义横跨多个文件。
 * 例如:可以把字段、属性和构造函数放在一个文件中,而把方法放在另一个文件中。
 * 为此,只需在每个包含部分类定义的文件中对类使用partial关键字即可。
 
*/
using  System ;
interface  ImyInterface1
{
    
void  dosomething();
}
interface  ImyInterface2
{
    
void  dosomethingelse();
}

#region  这两个类等同于下一个类

public   partial   class  myClass:ImyInterface1
{
    
public   void  dosomething()
    {
        Console.WriteLine (
" 接口1的方法 " );
    }
}
public   partial   class  myClass:ImyInterface2
{
    
public   void  dosomethingelse()
    {
        Console.WriteLine (
" 接口2的方法 " );
    }
}

#endregion

#region  等同于上面两个类

// public class myClass:ImyInterface1,ImyInterface2
// {
//     public void dosomething()
//     {
//         Console.WriteLine ("接口1的方法");
//     }
//     public void dosomethingelse()
//     {
//         Console.WriteLine ("接口2的方法");
//     }
// }

#endregion

class  Test
{
    
static   void  Main()
    {
        myClass a
= new  myClass ();
        a.dosomething ();
        a.dosomethingelse();
    }
}

转载于:https://www.cnblogs.com/gisland/archive/2009/08/16/1547494.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值