How to print 2D array to console in C#

后端 未结 10 1598
野性不改
野性不改 2020-12-06 22:59

I dont\'t have any code for this, but I do want to know how I could do this. I use visual studio 2010 C# if that matters.

Thanks

Jason

10条回答
  •  时光取名叫无心
    2020-12-06 23:29

    int[,] matrix = new int[2, 2] { {2, 2}, {1, 1} };
    
    for (int i = 0; i < matrix.GetLength(0); i++)
    {
        for (int k = 0; k < matrix.GetLength(1); k++ )
        {
            //put a single value
            Console.Write(matrix[i,k]);
        }
        //next row
        Console.WriteLine();
    }
    

提交回复
热议问题