How to return two values from a function in C#

1 Answer

0 votes
using System;

class Program
{
    static (int x, int y) f() {
        var x = int.MaxValue;
        var y = int.MinValue;
     
        return (x, y);
    }
    static void Main() {
        var (a, b) = f();
 
        Console.WriteLine($"a = {a} b = {b}");
    }
}



 

 
 
 
 
/*
run:
 
a = 2147483647 b = -2147483648
 
*/

 



answered Feb 4, 2023 by avibootz

Related questions

1 answer 170 views
1 answer 141 views
2 answers 224 views
4 answers 319 views
5 answers 397 views
...