开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜