Cannot convert from List to List

前端 未结 6 1387
庸人自扰
庸人自扰 2020-11-22 10:39

I\'m trying to pass A list of DerivedClass to a function that takes a list of BaseClass, but I get the error:

cannot convert from 
         


        
6条回答
  •  失恋的感觉
    2020-11-22 11:16

    If you could write

    List bcl = new List(); 
    

    you could call

    var instance = new AnotherClassInheritingFromBaseClass();
    bc1.Add(instance);
    

    Adding an instance which is not a DerivedClass to the list.

提交回复
热议问题