Should I always return IEnumerable instead of IList?

后端 未结 14 1997
一生所求
一生所求 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:32

    I might be a bit off here, seeing that no one else suggested it so far, but why don't you return an (I)Collection?

    From what I remember, Collection was the preferred return type over List because it abstracts away the implementation. They all implement IEnumerable, but that sounds to me a bit too low-level for the job.

提交回复
热议问题