What interface should my service return? IQueryable, IList, IEnumerable?

后端 未结 7 2219
孤独总比滥情好
孤独总比滥情好 2021-01-31 23:26

Imagine I have a SearchService layer that has a method to search all cars starting with a certain string;

public static class Searcher{
    public IAnInterface&l         


        
7条回答
  •  臣服心动
    2021-01-31 23:35

    Always go with IEnumerable unless you have a serious reason not to. You can then implement the getter with yield return.

    IQueryable is a totally different kettle of fish. Not something you'd casually implement as an alternative to a typical in-memory container.

    Of the rest, there is a major different between IEnumerable and the others: it's readonly.

提交回复
热议问题