C#.NET - How can I get typeof() to work with inheritance?

后端 未结 6 2382
醉话见心
醉话见心 2021-02-18 22:47

I will start by explaining my scenario in code:

public class A { }

public class B : A { }

public class C : B { }

public class D { }

public c         


        
6条回答
  •  没有蜡笔的小新
    2021-02-18 23:12

    Edit: this answers the question in the thread title. cdm9002 has the better answer to the problem as described in the full post.

    typeof(B).IsAssignableFrom(c.GetType())
    

提交回复
热议问题