Two Dimensional Array or 2D Array in C#

Two Dimensional Array or 2D Array


First We Use Two Dimensional Array First is Row &  Second is Column i.e[2,3] Using in C#.

              C# Coding

Row Length


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[,] array = new string [2,3] { { "One", "Two","Three" }, { "Four", "Five","Six"} };
      
        for (int i = 0; i < 2; i++)

        {

            for (int j = 0; j <array.GetLength(0); j++)

            {

                Response.Write(array[i,j] + ",\r");

            }
        }
    }

}

 Output








Column Length

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[,] array = new string [2,3] { { "One", "Two","Three" }, { "Four", "Five","Six"} };
      
        for (int i = 0; i < 2; i++)

        {

            for (int j = 0; j <array.GetLength(1); j++)

            {

                Response.Write(array[i,j] + ",\r");

            }
        }
    }
}


Output





0 comments:

Post a Comment