is vs typeof

前端 未结 4 1933
遇见更好的自我
遇见更好的自我 2020-11-30 19:28

Which of these pieces of code is faster?

if (obj is ClassA) {}

if (obj.GetType() == typeof(ClassA)) {}

Edit: I\'m aware that they don\'t d

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 20:10

    This should answer that question, and then some.

    The second line, if (obj.GetType() == typeof(ClassA)) {}, is faster, for those that don't want to read the article.

    (Be aware that they don't do the same thing)

提交回复
热议问题