码迷,mamicode.com
首页 > Windows程序 > 详细

C# - as

时间:2014-10-28 20:10:04      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:as   c#   



You can use the as operator to perform certain types of conversions between compatible reference types or nullable types.

The as operator is like a cast operation. However, if the conversion isn‘t possible, as returns null instead of raising an exception. Consider the following example:

expression as type

The code is equivalent to the following expression except that the expression variable is evaluated only one time.

expression is type ? (type)expression : (type)null
Note that the as operator performs only reference conversions, nullable conversions, and boxing conversions. The as operator can‘t perform other conversions, such as user-defined conversions, which should instead be performed by using cast expressions.

C# - as

标签:as   c#   

原文地址:http://blog.csdn.net/troubleshooter/article/details/40543763

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!