.NET/C#: check for exact type: simple things are always a good solution (via: Stack Overflow)
Posted by jpluimers on 2013/10/17
A while ago, I bumped into a situation where someone had tried to solve the problem below with a convoluted reflection based solution for this seemingly simple problem:
class A {}
class B : A {}
B b = new B();
if(b is A) // this should return false
And indeed the solution is simple: replace the “b is a” with this:
b.GetType() == typeof(A)
Thanks StackOverflow users ChaosPandion and John K.
–jeroen






Leave a comment