Is the is operator only syntactic sugar for the IsInstanceOfType method

Are the following code snippets equivalent?

class a
{}

class b:a
{}

b foo=new b();

// here it comes

foo is a

// ... matches the ...

typeof(a).isinstanceoftype(foo)

Or maybe one of the other type methods comes close to the is operator. e.g. "IsAssignableFrom" or "IsSubclassOf"

+5
source share
3 answers

No no. In fact, if you look in IsInstanceOfType, you will see that the first line of code actually does a comparison using is, which will actually result in StackOverflowExceptionif so.

The operator isresults in an operation isinstin the IL code.

+3

, is .

+6

This is not the same as being istranslated to isinst , whereas it IsInstanceOfis a regular virtual call Type.

+4
source

All Articles