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);
}
}
}
相关阅读 更多 +