- public interface ITestA {
- /*
- * 不加下面这一句输出是
- * Test.TestA
- * ITestAHelper.TestA
- * 加上后输出是
- * Test.TestA
- * Test.TestA
- */
- //void TestA();
- }
- public static class ITestAHelper
- {
- public static void TestA(this ITestA obj)
- {
- Console.WriteLine("ITestAHelper.TestA");
- }
- }
- public interface ITestB { }
- public static class ITestBHelper
- {
- public static void TestB(this ITestB obj)
- {
- Console.WriteLine("ITestBHelper.TestB");
- }
- }
- public class Test : ITestA, ITestB
- {
- //此方法与ITestA的TestA()扩展方法相同
- public void TestA()
- {
- Console.WriteLine("Test.TestA");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Test obj1 = new Test();
- //下面分别测试2种TestA()调用方式
- obj1.TestA();
- ((ITestA)obj1).TestA();
- Console.ReadKey();
- }
- }