Return
using System;
// Return statement returns flow of control from a method to the caller, optionally passing back a return value
public class ReturnDemo
{
public static string display()
{
return "Inside display"; /*here return type of the method display is
String,so it returns a string value */
}
public static void show()
{
Console.WriteLine("Inside show");
return; //returns with no value
}
static void Main(String[] args)
{
String message = display(); // Calls disaplay and the string value returned by the method display is stored in 'message'.
Console.WriteLine(message);
show(); // Calls show which returns nothing.
Console.ReadLine();
}
}
Output:
Inside display
Inside show