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.
1.4m articles
1.4m replys
5 comments
57.0k users