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

论坛 期权论坛 脚本     
niminba   2021-5-23 02:32   222   0

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)

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP