Monday, March 26, 2012

Simple Code Analysis request

Hi

I would appreciate being clarified simple peace of code,

protected void ShowDailyEvents()
{
DateTime d = MyCalendar.SelectedDate;
DataSet dataSet = LoadMyCalendarData();
if (dataSet == null)
{
return;
}

more code... bla bla
}

I dont understand whats the role of "return" here.
There should be some work on the dataset, but theres just "return", does this just skip the if structure and continues to the rest of the code in the method or something else?

thanxThe 'return' will exit the routine. When you see a signature of 'void' on any method and you wish to exit the method prematurely, then you would use a 'return':

private void Method1(int b)
{
int a = 2;
if(b == a)
{
//exit Method1() and do no work
return;
}

//otherwise continue
Response.Write((a+b).ToString());
}

0 comments:

Post a Comment