yield keyword

June 17, 2007

“Yield”=> Contextual keyword introduced to c# 2.0. It is important for “lazy evaluation” and the performance of queries in LINQ. Yield can be used as a variable name in C#. When put before return it becomes a keyword.

“Lazy evaluation”=>Lazy evaluation means that until you iterate over the result of the query, the source of the query is not iterated.

Advantages=>yield allows one enumerable class to be implemented in terms of another. This enables the delay of execution of queries until the latest possible moment, skipping the generation of intermediate results that would drastically reduce performance. The query operators in LINQ operate on sequence. The result of a query is often another sequence.

Leave a Reply