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 171 views
2 answers 181 views
181 views asked Mar 14, 2017 by avibootz
1 answer 184 views
1 answer 205 views
1 answer 109 views
1 answer 141 views
1 answer 211 views
...