#28:Deferred Execution-Linq

Most of the Query Operators Execute only when they are enumerated(IEnumerator Type-Move Next),but not when constructed.

var item = new List<int>();
IEnumerable<int> result = item.Select(x => x*5);
//Query is Constructed
//But still the item will be added and output would be 10,15 instead of 10.
 //This is called deferred execution.Query executes only on enumerating(for-each) but not on construction.
foreach (var VARIABLE in result)

Note: Not All Query Operators involves Deferred Execution.For instance First Operator should Execute the Query when constructed and return the First Element.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s