Reputation: 6626
This is my first day using c#.
I think it is very easy :(.
What does return
do in this case:
if (flag == false)
{
MessageBox.Show("Not a number.Re-enter.");
txtnum.Clear();
txtnum.Focus();
return;
}
?
Upvotes: 1
Views: 1804
Reputation: 82654
It simply exits the method. So that no code after that return will be executed.
Upvotes: 15
Reputation: 3207
Return is used as a means of stopping the execution of a method. Once hit, nothing else in the method will be processed. It's no different than a function that requires an int to be returned an ends when "return myInt" is hit. Here, your function returns void, so return alone, without a variable, is sufficient.
Upvotes: 4