Should I always return IEnumerable instead of IList?

后端 未结 14 2028
一生所求
一生所求 2020-11-27 11:47

When I\'m writing my DAL or other code that returns a set of items, should I always make my return statement:

public IEnumerable GetRecentItems         


        
14条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 12:46

    as all have said it depends, if you don't want Add/Remove functioanlity at calling layer then i will vote for IEnumerable as it provides only iteration and basic functionality which in design prespective i like. Returning IList my votes are always againist it but it's mainly what you like and what not. in performance terms i think they are more of same.

提交回复
热议问题