B为一个类,ISay为一个接口。

方法1:

 

 

B b = new B();
if (b.GetType().GetInterface("ISay") != null)
{
//如果实现了接口“ISay”,...
}

 

方法2:

 

B b = new B();
if (b is ISay)
{
Console.WriteLine(
"类B实现了接口ISay");
}

 

 方法3:

 

B b = new B();
ISay say
= b as ISay;
if (say != null)
{
Console.WriteLine(
"类B实现了接口ISay");
}

 

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2021-08-14
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-30
  • 2021-11-23
  • 2021-10-14
  • 2022-12-23
相关资源
相似解决方案