[From 4.2]as,is,和强制转换

例子1:
if(o is Employee)
    Employee e = (Employee)o;
例子2:
Employee e = o as Employee;
例子3
Employee e = (Employee)o;
 
例子1和例子3相比:例子1永远不会报错,例子3一旦无法转换便会报错
例子2和例子1,例子3相比:比例子1效率更快,比例子3更快。
posted @ 2018-12-28 14:21  Real陈麟  阅读(152)  评论(0编辑  收藏  举报