How to loop over 2D string array in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        string[,] array = new string[2, 3];
        
        array[0, 0] = "c#";
        array[0, 1] = "c";
        array[0, 2] = "c++";
        array[1, 0] = "php";
        array[1, 1] = "java";
        array[1, 2] = "python";

        int bound0 = array.GetUpperBound(0);
        int bound1 = array.GetUpperBound(1);

        for (int i = 0; i <= bound0; i++) {
            for (int j = 0; j <= bound1; j++) {
                Console.WriteLine(array[i, j]);
            }
            Console.WriteLine();
        }
    }
}



/*
run:

c#
c
c++

php
java
python

*/

 



answered Aug 28, 2020 by avibootz

Related questions

1 answer 159 views
2 answers 174 views
174 views asked Mar 14, 2017 by avibootz
1 answer 174 views
1 answer 197 views
1 answer 100 views
1 answer 133 views
1 answer 202 views
...