When to use var or IEnumerable to store query result in LINQ?
Ans. You can use var or IEnumerable<T> to store the result of a LINQ query. You should take care of following
points while choosing between var and IEnumrable.
var IEnumerable
Use var type when you want to make a "custom" type
on the fly.
Use IEnumerable when you already know the type of
query result.
var is also good for remote collection since var is an
IQueryable type that executes query in SQL server
with all filters.
IEnumerable is good for in-memory collection.
Ans. You can use var or IEnumerable<T> to store the result of a LINQ query. You should take care of following
points while choosing between var and IEnumrable.
var IEnumerable
Use var type when you want to make a "custom" type
on the fly.
Use IEnumerable when you already know the type of
query result.
var is also good for remote collection since var is an
IQueryable type that executes query in SQL server
with all filters.
IEnumerable is good for in-memory collection.
Comments
Post a Comment