Goodspeed

导航

2014年6月29日 #

为什么泛型不支持协变性?

摘要: 假设class S { }class A : S { }class B : S { }下面的代码是可以编译通过的S[] array = new A[5];array[0] = new B();List list = new List();运行结果:第一行代码是可以编译通过的第二行代码运行时报错第三行... 阅读全文

posted @ 2014-06-29 23:38 Goodspeed 阅读(458) 评论(0) 推荐(0) 编辑

可空值类型与值类型这间的转换

摘要: int s = 5;int? s_null;long t;long? t_null;t = s; //隐式转换 S -> Ts = (int)t; //显示转换 T -> Ss_null = s; //隐式转换 S -> S?s = (int)s_null; //显示转换 S? -> Tt_null... 阅读全文

posted @ 2014-06-29 23:21 Goodspeed 阅读(930) 评论(0) 推荐(0) 编辑