By 22/07/2015 5 Comments

C# Return Statement

  • C# return statement is used to exit from a class method and bypassed or ignored the remaining code which is in that method.
  • It returns the value of same type as same as method type is and execution transfers back to caller of the method.
  • If method is not a return type it is a void type then return keyword does not return any type of value, it simply declare return without specifies an expression or value.


using System;
namespace csharpBasic
    // Start class definition / declaration.
    class Program
        // Static main method void type declaration.
        static void Main(string[] args)

            // Following statement creates an object of class Test
            Test objTest = new Test();

            // Calls DisplayMessage() which returns a string message and assign to message variable.
            string message = objTest.DisplayMessage();

            // Print message. 

        } // End of main method definition. 
    } // End of class.

    class Test
        // Following is a method declaration of string type.
        public string DisplayMessage()
            /* following a return statement is declared which 
               returns a string literals or string type expression 
               to caller of the method.
            return "C# is an Object Oriented Programming Language.";
             The Output will be:
             C# is an Object Oriented Programming Language.

Next Tutorial →

← Previous Tutorial

Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .