Return multiple values to a method caller

Ash picture Ash · Apr 14, 2009 · Viewed 761.5k times · Source

I read the C++ version of this question but didn't really understand it.

Can someone please explain clearly if it can be done and how?

Answer

Hadas picture Hadas · Apr 23, 2012

In C# 7 and above, see this answer.

In previous versions, you can use .NET 4.0+'s Tuple:

For Example:

public Tuple<int, int> GetMultipleValue()
{
     return Tuple.Create(1,2);
}

Tuples with two values have Item1 and Item2 as properties.