A return statement is used for returning value to the caller from the called function. A very  easy example is mentioned below in a program that demonstrate the return statement very clearly and easy.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Return_Statements
{
    class Program
    {
        public int Add(int n1, int n2)
        {
            // returns the add of n1 and n2
            return n1 + n2;
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            int result;
            // calling the function add that will return 9 to the result vaiable.
            result = p.Add(3, 6);
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *