Are the following code snippets equivalent?
class a
{}
class b:a
{}
b foo=new b();
//here it comes
foo is a
//…is the same as…
typeof(a).isinstanceoftype(foo)
Or maybe one of the other Type Methods map closer to the is operator.
e.g. “IsAssignableFrom” or “IsSubclassOf”
No it’s not. In fact, if you peek into
IsInstanceOfTypeyou will see that the very first code line actually performs a comparison usingis, which would effectively lead to aStackOverflowExceptionif that was the case.The
isoperator leads to anisinstoperation in the IL code.