0

For example I want to return multiple value from this function

public int,int Sum(int a,int b) 
{
   return (a,b);
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

2 Answers2

1

In the code below, you notice that we have defined a function, calculated the minimum and maximum values and then returned a Tuple of type<int,int> back to the calling method. This lets the compiler know that a tuple having 2 integer values is being returned back.

public Tuple<int,int> MultipleReturnsFromSUM(int a, int b)  
{  
    int min, max;  
    if (a > b)  
    {  
        max = a;  
        min = b;  
    }  
    else  
    {  
        max = b;  
        min = a;  
    }  
    return new Tuple<int, int>(min, max);  
} 
0

For your case just use value tuple.

public (int,int) Sum(int a,int b) 
{
   return (a,b);
}
Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116