How to return 2D array from method in C#

1 Answer

0 votes
using System;

class Program
{
    static int[,] GetArray() {
        int[,] arr = new int[2, 3] { {6, 7, 8,}, {9, 2, 1} };
        return arr;
    }
    static void Main() {
        int[,] arr = GetArray();

        foreach(int n in arr)
            Console.Write($"{n}\t");
    }
}



/*
run:

6	7	8	9	2	1	

*/

 



answered Dec 13, 2020 by avibootz

Related questions

1 answer 145 views
145 views asked Dec 12, 2020 by avibootz
1 answer 165 views
165 views asked Jan 2, 2022 by avibootz
1 answer 142 views
3 answers 351 views
1 answer 157 views
2 answers 225 views
1 answer 240 views
...