Is there a better way to do this, where C:B:A:
The problem with IsSubclassOf() is that if the type is A, it returns false.Code:if (X.GetType().IsSubclassOf(typeof(A)) ||
X.GetType() == typeof(A))
{
A bob = (A)X;
}
Printable View
Is there a better way to do this, where C:B:A:
The problem with IsSubclassOf() is that if the type is A, it returns false.Code:if (X.GetType().IsSubclassOf(typeof(A)) ||
X.GetType() == typeof(A))
{
A bob = (A)X;
}
Code:if(X is A) { ... }
Can't get much more simple than that. Cheers!
Code:A bob = X as A;
if (bob != null)
{
(...)
}