IEnumerable VS IList VS IQueryable

后端 未结 3 1787
无人及你
无人及你 2020-12-13 07:43

New to the MVC.net scene (and .net for that matter), but seems I find a wide array of options when wanting to populate a \"list\" with data. In my case at the moment, I\'d

3条回答
  •  醉梦人生
    2020-12-13 08:07

    My rules of thumb:

    • Use a List when you have to add, remove, or refer to an item by index.

    • Use a IQueryable when you have to run ad-hoc queries against it.

    • Use IEnumerable by default.

    It looks like you're already doing the query "in" your database, so I'd suggest using the simplest version: IEnumerable to simply be able to loop through the results.

提交回复
热议问题