O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Specifying the Return Type

The return type of a method can be either a type or void. This indicates what a caller of the method will get (under normal circumstances) in return for calling the method. When a type is specified, all execution paths through the method’s body should reach a point where the return keyword is used to hand back a result to the caller. As you see later, it’s also possible for a method to throw an exception. For example:

public static int Div(int n, int d){    if (d == 0)        throw new ArgumentOutOfRangeException("d");    return n / d;}

In the preceding example, the expression n / d results in an int value that can be returned to the caller by using the return keyword. If the denominator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required