110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
C c = new C();
c.foo();
c.bar();
c.aMethod();
I1 i1 = c;
i1.foo();
// i1.bar(); 错误
(i1 as I2).bar();
//(i1 as I2).aMethod(); 错误
(i1 as C).aMethod();
i1.GetType().GetMethods().Where(x => x.Name == "aMethod").First().Invoke(i1, new object[] { });
}
}
interface I1
{
void foo();
}
interface I2 : I1
{
void bar();
}
class C : I2
{
public void bar()
{
Console.WriteLine("bar");
}
public void foo()
{
Console.WriteLine("foo");
}
public void aMethod()
{
Console.WriteLine("aMethod");
}
}
}