"is" operator efficiency

is "is" lightweight? Specifically, for checking whether a reference to a base type is a certain derived type. I am considering doing this in a method which I want to be as fast as possible.
[199 byte] By [omgtifbs] at [2007-12-25]
# 1

Yes! is operator is lightweight and fast, but if you need something like Checking Type and Then parsing it to that time, Then use a better and recommended way that is as Operator:

Code with is:

if(aControl is Button)

{

Button b = (Button) button1;

}

Code with as:

Button b = button1 as Button;

if(b == null) // was not a Button

{

// Do Something

}

else // is Button and Also Parsed

{

//Do Something

}

So its a short and fast too, So it depends on your use. as eliminates double casting of a type from from is and then by real casting.

Hope it help!

Best Regards,

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Its not exactly lightweight, but it is the fastest way of determining whether an instance is of a particular type (unless you want to check the type and then convert it, in which you should probably use 'as').
CommonGenius.com at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3
I'm not 100% certain, but I believe "is" is faster at checking for a class than it is checking for an interface.
Nimrand at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# Language...