首页 > 代码库 > C# - as
C# - as
You can use the as operator to perform certain types of conversions between compatible reference types ornullable 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 theexpression variable is evaluated only one time.
expression is type ? (type)expression : (type)nullNote that theas operator performs only reference conversions, nullable conversions, and boxing conversions. Theas operator can‘t perform other conversions, such as user-defined conversions, which should instead be performed by using cast expressions.
C# - as
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。