"markusszil" <(E-Mail Removed)> wrote in message
news:98854780-B727-4E69-BD20-(E-Mail Removed)...
> Hello all,
>
> (What may well be a)
> Dumb Question:
>
> How do I determine if 2 objects are of equivalent type? I need an
expression which evaluates true if left-hand-side of comparison is of same
type or inherits from rhs.
>
> I was hoping to use "is" or "as" but these seem to require explicit type
names, they can't use type objects.
>
> Some pseudo C# showing what I would like:
>
> public class ClassA { }
> public class ClassB:ClassA{ }
>
> ClassA a=new ClassA();
> ClassB b=new ClassB();
>
> if (b is ClassA) { } // this works and, in this case, should
evaluate true
>
> if (b is a.GetType()) { } // this is what I want, but this line
generates syntax error - a is not a type
>
if(a.GetType().IsAssignableFrom(b.GetType()))
{
//Whatever
}
Regards /Magnus Lidbom
|