Why use IList or List?

后端 未结 10 677
离开以前
离开以前 2020-11-29 15:58

I know there has been a lot of posts on this but it still confuses me why should you pass in an interface like IList and return an interface like IList back instead of the c

10条回答
  •  死守一世寂寞
    2020-11-29 16:38

    Short Answer:

    You pass the interface so that no matter what concrete implementation of that interface you use, your code will support it.

    If you use a concrete implementation of list, another implementation of the same list will not be supported by your code.

    Read a bit on inheritance and polymorphism.

提交回复
热议问题