开发者

What does the `is` operator do in C#?

开发者 https://www.devze.com 2023-02-05 19:08 出处:网络
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 e

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

0

精彩评论

暂无评论...
验证码 换一张
取 消