IList vs IEnumerable for Collections on Entities

后端 未结 2 1029
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 10:23

When I have entities in my domain with lists of things, should they be exposed as ILists or IEnumerables? E.g. Order has a bunch of OrderLines.

2条回答
  •  北海茫月
    2020-11-27 11:03

    Most of the time I end up going with IList over IEnumerable because IEnumerable doesn't have the Count method and you can't access the collection through an index (although if you are using LINQ you can get around this with extension methods).

提交回复
热议问题