Type Checking: typeof, GetType, or is?

前端 未结 14 2280
北海茫月
北海茫月 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:26

    The last one is cleaner, more obvious, and also checks for subtypes. The others do not check for polymorphism.

提交回复
热议问题