How to print 2D array to console in C#

后端 未结 10 1604
野性不改
野性不改 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:36

    You should read MSDN:Using foreach with Arrays

    int[,] numbers2D = new int[3, 2] { { 9, 99 }, { 3, 33 }, { 5, 55 } };
    // Or use the short form:
    // int[,] numbers2D = { { 9, 99 }, { 3, 33 }, { 5, 55 } };
    
    foreach (int i in numbers2D)
    {
        System.Console.Write("{0} ", i);
    }
    

    // Output: 9 99 3 33 5 55

提交回复
热议问题