What is the C# equivalent to Java's isInstance()?

前端 未结 5 942
清歌不尽
清歌不尽 2020-12-13 16:54

I know of is and as for instanceof, but what about the reflective isInstance() method?

5条回答
  •  忘掉有多难
    2020-12-13 17:37

    just off the top of my head, you could also do:

    bool result = ((obj as MyClass) != null)
    

    Not sure which would perform better. I'll leave it up to someone else to benchmark :)

提交回复
热议问题