Logic and its application to Collections.Generic and inheritance

后端 未结 6 1854
猫巷女王i
猫巷女王i 2021-01-06 20:49

Everything inherits from object. It\'s the basis of inheritance. Everything can be implicitly cast up the inheritance tree, ie.

object me = new Person();
         


        
6条回答
  •  感情败类
    2021-01-06 21:34

    With linq extension methods you can do

    IEnumerable things = people.Cast();
    List things = people.Cast().ToList();
    
    
    

    Otherwise since you are strongly typing the list the implicit conversion isn't allowed.

    提交回复
    热议问题