When var or IEnumerable is used to store query result in LINQ?

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.

Tagged , . Bookmark the permalink.

Leave a Reply