How does the " is " operator work internally

Posted by JDMX on Stack Overflow See other posts from Stack Overflow or by JDMX
Published on 2010-05-24T15:33:13Z Indexed on 2010/05/24 15:41 UTC
Read the original article Hit count: 240

Filed under:

I want to compare the type of an object to a type to see if they are the same. I do not have the object, just the type of the object.

I can do type1 == type2 and get general equality

I can have a recursive loop where I repeat the above step for type1.BaseType until the BaseType is null.

I can do type1.GetInterface( type2.FullName ) != null to check if type2 is an interface of type1

If I put it all together, I get

if ( type2.IsInterface )
  return type1.GetInterface( type2.FullName ) != null;

while ( type1 != null ) {
  if ( type1 == type2 )
    return true;

  type1 = type1.BaseType;
}
return false;

Is that all the is keyword is. I cannot find the right keyword to plug into the Reflector search to find the function and a google search on "is" was not really helpful

© Stack Overflow or respective owner

Related posts about .NET