s

C# return statement edit button Edit

author
Rakesh Kumar Sutar | calendar 14 January 2021 | 1782

Introduction

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.

Example

using System;

namespace Hello_world
{
    class Program
    {
        static double CalculateArea(int r)
        {
            double area = r * r * Math.PI;
            return area;
        }
        static void Main(string[] args)
        {
            int radius = 5;
            double result = CalculateArea(radius);
            Console.WriteLine("The area is {0:0.00}", result);
        }
    }
}

Output