c# as vs is

在c# 中, is 是类型判断,结果为false或者true, 不会抛出异常。


Object o=new Object();

Boolean a1=(o is Object); //a1为true.
Boolean a2=(o is ClassA) ; //a2为false.
本文来自博客园-陈国立:http://www.tenpaya.com   原文地址:https://www.cnblogs.com/cgli/archive/2011/05/10/2041731.html

as是强制类型转换, 如果兼容可转换,则会返回对象类型的引用,否则返回null

 ComboBox combo = sender as ComboBox;

猜你喜欢

转载自www.cnblogs.com/FirstOpticalAuto/p/9105672.html
今日推荐