Essential C# Tuples  Suggest an edit

Return multiple values from a method

Tuples can be used to return multiple values from a method without using out parameters. In the following example AddMultiply is used to return two values (sum, product).

void Write()
    var result = AddMultiply(25, 28);

Tuple<int, int> AddMultiply(int a, int b)
    return new Tuple<int, int>(a + b, a * b);


53 700

Now C# 7.0 offers an alternative way to return multiple values from methods using value tuples More info about ValueTuple struct.

Table Of Contents
22 Enum
23 Tuples
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close