文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C# - Extension Method

C# - Extension Method

时间:2010-09-02  来源:zip's

使用Extension Method可以为接口提供一个默认实现

扩展方法扩展接口,等效于带有默认实现的接口方法
namespace ExtensionMethod
{
public interface IMyInterface
{
void foo(bool b);
}
public static class MyInterfaceExt
{
public static void Disabled(this IMyInterface c, bool b)
{
c.foo(b);
}
}

class MyCls : IMyInterface
{
public void foo(bool b)
{
Debugger.Break();
}
}

class Program
{
static void Main(string[] args)
{
MyCls c
= new MyCls();
c.Disabled(
true);
}
}
}

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载