Search code examples
c#return

Return multiple values to a method caller


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

Can someone please explain clearly if it can be done in C#, and how?


Solution

  • 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.