CSharp - Statement return statement


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.


using System;
class MainClass/*from w w  w. j a v a  2  s  . co  m*/
     public static void Main(string[] args)
     static decimal Add(decimal d)
         decimal p = d +10100m;
         return p;             // Return to the calling method with value