Click here to Skip to main content
15,918,808 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Need help with calling this method. Pin
Vimalsoft(Pty) Ltd6-Aug-09 3:40
professionalVimalsoft(Pty) Ltd6-Aug-09 3:40 
GeneralRe: Need help with calling this method. Pin
kaining896-Aug-09 3:58
kaining896-Aug-09 3:58 
GeneralRe: Need help with calling this method. Pin
Vimalsoft(Pty) Ltd6-Aug-09 4:04
professionalVimalsoft(Pty) Ltd6-Aug-09 4:04 
QuestionSet default input language of a text box Pin
benams6-Aug-09 1:56
benams6-Aug-09 1:56 
AnswerRe: Set default input language of a text box Pin
Abhishek Sur6-Aug-09 9:50
professionalAbhishek Sur6-Aug-09 9:50 
QuestionApplication Begin request is not getting called Pin
suzzain6-Aug-09 1:42
suzzain6-Aug-09 1:42 
Questionyield return Pin
vishwjeet6-Aug-09 1:32
vishwjeet6-Aug-09 1:32 
AnswerRe: yield return Pin
Abhishek Sur6-Aug-09 10:24
professionalAbhishek Sur6-Aug-09 10:24 
Iterator blocks are called when you want to fetch the data from the Enumerable.

Actually if you call the the function, it will not be called. Rather if you do a foreach on the Enumerable object the function will be called and will return you 10. Wink | ;)

Just change your code a bit as I did:

IEnumerable<int> arr = Documented.GetValuesUpto(10);
MessageBox.Show(arr.ToList<int>().Count.ToString());


public static IEnumerable<int> GetValuesUpto(int n)
{

    for (int ctr = 1; ctr <= n; ctr++)
    {

       yield return ctr;
    }
            
}


Put a breakpoint in the line IEnumerable<int> arr = Documented.GetValuesUpto(10);. and also a breakpoint within GetValueUpto block. You will see the function is called when we try to call ToList() rather than the actual call to GetValueUpto. This is the main advantage of iterator blocks.

Rose | [Rose] Rose | [Rose]

Abhishek Sur

My Latest Articles
Create CLR objects in SQL Server 2005
C# Uncommon Keywords
Read/Write Excel using OleDB

Don't forget to click "Good Answer" if you like t

Questionhow to get cursor position of the textbox Pin
ansriharsha6-Aug-09 1:25
ansriharsha6-Aug-09 1:25 
AnswerRe: how to get cursor position of the textbox Pin
Abhishek Sur6-Aug-09 10:46
professionalAbhishek Sur6-Aug-09 10:46 
AnswerRe: how to get cursor position of the textbox Pin
ansriharsha23-Aug-09 21:15
ansriharsha23-Aug-09 21:15 
GeneralRe: how to get cursor position of the textbox Pin
Abhishek Sur23-Aug-09 21:54
professionalAbhishek Sur23-Aug-09 21:54 
QuestionDesign a master page Pin
SUDHAKAR PALLAM6-Aug-09 1:01
SUDHAKAR PALLAM6-Aug-09 1:01 
QuestionAjax Refresh Without Timer Pin
platso_5885-Aug-09 23:33
platso_5885-Aug-09 23:33 
AnswerRe: Ajax Refresh Without Timer Pin
Christian Graus5-Aug-09 23:41
protectorChristian Graus5-Aug-09 23:41 
Questionlinkbutton ibn repeater control and based on linkbutton click different modal[poupextender have to show..., Pin
Member 38798815-Aug-09 23:21
Member 38798815-Aug-09 23:21 
AnswerRe: linkbutton ibn repeater control and based on linkbutton click different modal[poupextender have to show..., Pin
Abhishek Sur6-Aug-09 11:54
professionalAbhishek Sur6-Aug-09 11:54 
Questionaspx js Pin
epcode15015-Aug-09 22:44
epcode15015-Aug-09 22:44 
AnswerRe: aspx js Pin
Christian Graus5-Aug-09 23:42
protectorChristian Graus5-Aug-09 23:42 
QuestionWho know ExportPanel Ajax control in Dot net 2008? Pin
aeriscute5-Aug-09 22:32
aeriscute5-Aug-09 22:32 
QuestionAJAX Accordion - CSS Styling Issue Pin
Maynards5-Aug-09 22:18
Maynards5-Aug-09 22:18 
QuestionRange Validator Pin
janani135-Aug-09 22:00
janani135-Aug-09 22:00 
AnswerRe: Range Validator Pin
Arun Jacob5-Aug-09 22:06
Arun Jacob5-Aug-09 22:06 
AnswerRe: Range Validator Pin
Manas Bhardwaj5-Aug-09 22:14
professionalManas Bhardwaj5-Aug-09 22:14 
GeneralRe: Range Validator Pin
janani135-Aug-09 23:09
janani135-Aug-09 23:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.