Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

return (C# Reference)

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.

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

// statements_return.cs
using System;
class ReturnTest 
    static double CalculateArea(int r) 
        double area = r * r * Math.PI;
        return area;

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

The area is 78.54

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

  • Return statements

  • 8.9.4 The return statement

© 2015 Microsoft