Introduction:

Here we will explain how to use return statement in c# or what is the functionality of return statement or what is the  return statement in C# with example.

Description:

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

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Example
{
    class Program
    {
        public string GetName()
        {
            //returns the name
            return "Aditya Kumar Pate";
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            string result;
            //calling the function add that will return Aditya Kumar Pate to the result variable.
            result = p.GetName();
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

 

 

In this example the variable result calls the function GetName () the function GetName () returns Name to the result variable using return keyword.

 

Output


What is return statement in c#


I hope this Article will help to you.

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like