在一些C#代码中常常可以看到 //An Simple Example By Ray Linn class CarCollection :ICollection { IList list; public void Add(Car car) { list.Add(car); } .... function list for ICollection... public void listPrice() { foreach(Car car in list) System.Console.WriteLi…
问题示例 List<Integer>[] intListArr = new ArrayList<Integer>[8]; // 编译时报错 能看到这么看似没啥问题的一个简单语句甚至连编译都不会通过,为了能理解这里面的缘由,我们先得了解变型(Variant)的概念 变型(variant) 协变(covariant) 允许在子类出现的地方用超类替换(A feature which allows to substitute a subtype with supertype.) 逆变(co…