【问题标题】:Return the types of interfaces that a class implements C#返回类实现 C# 的接口类型
【发布时间】:2013-07-22 08:12:56
【问题描述】:

有没有办法获取类实现的接口类型。为了进一步解释这个问题,这就是我的意思。例如:

public interface ISomeInterface
{

}

public class SomeClass : ISomeInterface
{

}

public class SecondClass
{

    ISomeInterface someclass;

    public SecondClass()
    {
        someclass = new SomeClass();
    }

    public Type GetInterfaceInSomeWay()
    {
        //some code
    }

}

我需要填写评论区。提前感谢您的帮助,社区!

【问题讨论】:

标签: c# class interface


【解决方案1】:

typeof(SomeClass).GetInterfaces()

【讨论】:

    【解决方案2】:
    foreach (Type tinterface in typeof(SomeClass).GetInterfaces())
    {
       Console.WriteLine(tinterface.ToString());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-06
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多