The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,483 other followers

Archive for October 17th, 2013

.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.


via c# check for exact type – Stack Overflow.

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

%d bloggers like this: