Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i read about the return jump statmnet in c# but i didnt get the meaning of the last part of the word
"This statement terminates the execution of the method and <big><big><big></big></big>returns the control to the calling method</big>"


What I have tried:

read about it in microsoft docs
Posted
Updated 9-Jul-19 12:01pm

C#
void SomeMethod()
{
   // ...
   return;
}

void Main()
{
   // Code executed before the call to the SomeMethod method
   SomeMethod();
   // Code executed after the SomeMethod method has exited
}

In the Main method, there is a call to the SomeMethod method. Thus, the execution goes from the Main method to the SomeMethod method. When the return; statement is reached, the SomeMethod exits and returns execution to the calling method, i.e. the Main method.
 
Share this answer
 
Comments
Member 14479161 9-Jul-19 21:00pm    
Hi
Here the caller method is the main Method correct
phil.o 10-Jul-19 2:55am    
Yes.
Member 14479161 10-Jul-19 10:37am    
thanks
What this means is that if the conditions are met, an earlier departure from the routine occurs, and the rest of the routine is ignored. In this example, calls to generate.email() will return a -1 right away if the input value not a valid email address, and not go through the overhead of building objects and running their methods. While you could just put the rest of the code in an else wrap, you'd stilll have to go through all of the code when you are debugging.
C#
public static class generate{
  public int email(string emailAddress = "") {
    if (IsValidAddress(emailAddress) == false) {       return -1;     }

    // build smtp object
    // build mail message
    // try to send message
    // log results

   return send.resultvalue;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900