Difference between interface as type constraint and interface as parameter?

前端 未结 5 1358
暖寄归人
暖寄归人 2021-02-13 14:30

If I wanted to create a method that takes an instance of IList as a parameter (or any other interface, but let\'s use IList as an example), I could cre

5条回答
  •  梦如初夏
    2021-02-13 15:07

    if Foo2 returns void, it doesn't really matter. But suppose Foo2 returned a modified version of the list. With an IList parameter, the best it could do is return another IList. But with an IList constraint, it could return any type the caller wants assuming that type implements IList

提交回复
热议问题