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 do the same thing.
Does it matter which is faster, if they don't do the same thing? Comparing the performance of statements with different meaning seems like a bad idea.
is tells you if the object implements ClassA anywhere in its type heirarchy. GetType() tells you about the most-derived type.
is
ClassA
GetType()
Not the same thing.
2.1m questions
2.1m answers
60 comments
57.0k users