IT. Expert System.

C#

return


The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted. If the return statement is inside a try block, the finally block, if one exists, will be executed before control returns to the calling method.

Syntax:
return variable;

return value;


Example:

using System;

class Program
{
    static void Main()
    {
	// Call four methods and store their return values.
	int value1 = MethodA();
	string value2 = MethodB(true);
	string value3 = MethodB(false);
	int value4 = MethodC(5, 2);

	// Display the results.
	Console.WriteLine(value1);
	Console.WriteLine(value2);
	Console.WriteLine(value3);
	Console.WriteLine(value4);

	// Invoke a void method.
	MethodD();
    }

    static int MethodA()
    {
	// This method returns a constant integer.
	return 100;
    }

    static string MethodB(bool flag)
    {
	// This method returns a string reference based on the flag.
	return flag ?
	    "cat" :
	    "dog";
    }

    static int MethodC(int operand1, int operand2)
    {
	// This method returns an integer based on an expression.
	return (operand1 * 10) + operand2;
    }

    static void MethodD()
    {
	// This method uses a return statement with no expression (void).
	Console.WriteLine("MethodD executed");
	return;
    }
}
/*
Output

100
cat
dog
52*/


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1389 / . Delta: 0.00545 с