Type Checking: typeof, GetType, or is?

前端 未结 14 2272
北海茫月
北海茫月 2020-11-22 00:49

I\'ve seen many people use the following code:

Type t = typeof(obj1);
if (t == typeof(int))
    // Some code here

But I know you could also

14条回答
  •  迷失自我
    2020-11-22 01:33

    I believe the last one also looks at inheritance (e.g. Dog is Animal == true), which is better in most cases.

提交回复
热议问题