How to convert a rectangular array to a one-dimensional array in C#

1 Answer

0 votes
using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
       string[,] rectangularArray = new string[3, 3] { 
            {"a", "b", "c"}, 
            {"d", "e", "f"}, 
            {"g", "h", "i"}};
            
        var result = rectangularArray.Cast<object>().ToArray();

        Console.Write(string.Join(", ", result));
    }
}


/*
run:

a, b, c, d, e, f, g, h, i

*/

 



answered Mar 13, 2025 by avibootz
...