What does the `is` operator do in C#?
What does the is
开发者_C百科 operator do in C#?
The "is" operator takes 2 operands and returns a boolean value representing the ability for the first operand to be cast into the second operand. For example:
if(object1 is ClassA) //returns true if object1 is derived from ClassA or can be cast into ClassA.
An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.
Source: http://msdn.microsoft.com/en-us/library/scekt9xw(v=vs.80).aspx
精彩评论