CoDebate

Debating Code - [ASP.NET, C#, Sql Server, VB.NET]

Wednesday, March 28, 2018

C# - 'yield' keyword (Kenneth Truyers)

There are so many least-used facilities are still out there within C#. 'Yield' keyword is one such thing!

When searched for learning, I have been getting a lot of examples however most of the examples use 'static' keyword too! Feeling static as irrelevant in this case, I was looking for examples without it.

Later, I came across a wonderful article and would like the readers to go-through it : Kenneth-Truyers - 'yield' keyword!. Thanks to Kenneth (Microsoft MVP) for throwing a good light on this topic!

A gist from his article : (Courtesy : Kenneth Truyers)

  • Yield retains the state of the iteration. (without having to use static keyword or additional collections)
  • Yield returns a placeholder of list (IEnumerable) to the client promising that it would give list of elements on-demand.
  • Yield gives the ability to defer execution. This is evident from his second example.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Thanks for visiting! Happy Programming :)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

posted by Karthikeyan @ 2:39 AM

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home