Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

What is difference between

1. var v1 = (From m in context.Customers select m);
2. var v1 = (From m in context.Customers select m).ToList();
Posted

1 solution

Second one creates a List from the IEnumerable returned by the query.

This is handy if you want to force the enumeration of the items to happen immediately, as Linq employs deferred execution[^] which means the query isn't fully executed until the items are enumerated.

In some cases it's important that the sequence is only enumerated once, and in those cases it's very convenient to immediately create a list or array from the query and return that.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900