Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Friday, March 3, 2017

how to use Yield Keyword in C# or Asp.net C#?

How to use Yield Keyword in C#:


The yield keyword is used to define a function which returns an IEnumerable or 
IEnumerator (as well as their derived generic variants) whose values are generated
 lazily as a caller iterates over the returned collection. Read more about the purpose in 
the remarks section.
The following example has a yield return statement that's inside a for loop.
public static IEnumerable<int> Count(int start, int count)
{
    for (int i = 0; i <= count; i++)
    {
        yield return start + i;
    }
}
Then you can call it:
foreach (int value in Count(start: 4, count: 10))
{
    Console.WriteLine(value);
}

No comments:

Post a Comment