2-dim array

The two dimensional arrays in C# are simple row by column matrix. The following is an example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Collections;


namespace ConsoleApplication6
{
    
    class Program
    {
        static void Main(string[] args)
        {
            int[,] twodim = new int[3, 4];

            twodim[0, 0] = 19;
            twodim[0, 1] = 14;
            twodim[0, 2] = 13;
            twodim[0, 3] = 32;
            twodim[1, 0] = 12;
            twodim[1, 1] = 14;
            twodim[1, 2] = 14;
            twodim[1, 3] = 24;
            twodim[2, 0] = 11;
            twodim[2, 1] = 18;
            twodim[2, 2] = 17;
            twodim[2, 3] = 47;

            for (int i=0; i<twodim.GetLength(0); i++)
            {
                for(int j=0; j<twodim.GetLength(1); j++)
                {
                    Console.Write(twodim[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}

 

 

Add a Comment

Your email address will not be published. Required fields are marked *