How to set values to elements of 2D array of strings in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] arr2d = new string[3, 2];

            arr2d[0, 0] = "c#";
            arr2d[1, 1] = "java";
            arr2d[2, 0] = "c++";

            int ub0 = arr2d.GetUpperBound(0);
            int ub1 = arr2d.GetUpperBound(1);
            for (int i = 0; i <= ub0; i++)
            {
                for (int j = 0; j <= ub1; j++)
                {
                    Console.Write(arr2d[i, j] + "    ");
                }
                Console.WriteLine();
            }
        }
    }
}

/*
run:
  
c#
    java
c++
  
*/

 



answered Jan 7, 2017 by avibootz
...