Logic and its application to Collections.Generic and inheritance

后端 未结 6 1828
猫巷女王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:23

    OK, everyone who has used generics in .net must have run into this at one point or another.

    Yes, intuitively it should work. No, in the current version of the C# compiler it doesn't.

    Eric Lippert has a really good explanation of this issue (it's in eleven parts or something and will bend you mind in places, but it's well worth the read). See here.

    edit:

    dug out another relevant link, this one discusses how java handles this. See here

提交回复
热议问题