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 77 views
1 answer 163 views
1 answer 134 views
2 answers 211 views
4 answers 303 views
5 answers 382 views
...