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

C#中的is和as操作符区别小结

时间:2017-12-07 00:20:12      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:bottom   技术分享   nic   info   color   har   www.   ima   区别   


1. is 是验证操作对象是不是自己希望的

运算公式:对象  is  类型

返回true:对象是指定类型

返回false:对象不是指定类型


2. as 是将对象转换成指定类型

运算公式:对象 as 类型

转换成功:对象的类型就是指定的类型

转换失败:返回null

注意: The  “is” and “as” operator must be used with a reference type or nullable type (example:’int’ is a non-nullable value type)

除声明外,跑步客文章均为原创,转载请以链接形式标明本文地址
  C#中的is和as操作符区别小结

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23176.html






相关内容

C#中的is和as操作符区别小结

标签:bottom   技术分享   nic   info   color   har   www.   ima   区别   

原文地址:http://www.cnblogs.com/paobuke/p/7994961.html

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