Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

return (C# Reference)

Updated: July 2008

The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted.

If the return statement is inside a try block, the finally block, if one exists, will be executed before control returns to the calling method.

In the following example, the method A() returns the variable Area as a double value.

class ReturnTest 
{
    static double CalculateArea(int r) 
    {
        double area = r * r * Math.PI;
        return area;
    }

    static void Main() 
    {
        int radius = 5;
        double result = CalculateArea(radius);
        Console.WriteLine("The area is {0:0.00}", result);

        // Keep the console open in debug mode.
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}
// Output: The area is 78.54

For more information, see the following sections in the C# Language Specification:

  • 5.3.3.12 Return statements

  • 8.9.4 The return statement

Date

History

Reason

July 2008

Added note concerning try-finally.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft