C#方差问题:将列表<派生>赋值为列表<base>
class Animal { }class Giraffe : Animal { }static void Main(string[] args){ // Array assignment works, but... Animal[] animals = new Giraffe[10]; // implicit... List<Animal> animalsList = new List<Giraffe>(); // ...and explicit casting fails List<Animal> animalsList2 = (List<Animal>) new List<Giraffe>();}
料青山看我应如是
慕侠2389804