CSharp - Statement return statement

Introduction

return statement would exit the method and program will run the first statement after the method.

For a method which has a non-void return type and the return statement must return an expression of the method's return type.

If the method is void, you can just use return; to exit a method.

A return statement can appear anywhere in a method except in a finally block.

The following Add() method returns decimal type.

Demo

using System;
class MainClass/*from www .jav a2  s .c o m*/
{
     public static void Main(string[] args)
     {
         Console.WriteLine(1234M);
         Console.WriteLine(Add(1234M));
     }
     static decimal Add(decimal d)
     {
         decimal p = d +10100m;
         return p;             // Return to the calling method with value
     }
}

Result