HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Return multiple values to a method caller

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
returnmethodmultiplecallervalues

Problem

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 GetMultipleValue()
{
     return Tuple.Create(1,2);
}


Tuples with two values have Item1 and Item2 as properties.

Code Snippets

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

Context

Stack Overflow Q#748062, score: 810

Revisions (0)

No revisions yet.