Professional Documents
Culture Documents
Arrays:: Single Dimension Array
Arrays:: Single Dimension Array
Arrays are used to store collection of data. It stores a fixed-size sequential collection of
elements of the same data type. Instead of declaring different individual variables, we declare
one array variable. Specific element in the array is accessed by an index.
First Element last Element
Classification of Arrays:
There are three different types of Arrays
3. Jagged Array
using System;
namespace Array
{
class Program
{
static void Main(string[] args)
{
//There are different ways to initialize arrays in C#
some are as follows:
2.
Output:
2. Multi-Dimension Arrays
Following example show the initialization and execution of the multi-Dimension
arrays.
using System;
namespace Array
{
class Program
{
static void Main(string[] args)
{
//there are different ways to initialize arrays in C# some are as follows:
Console.WriteLine("Array 1 Data\n");
int[,] arr = new int[2, 5] { { 0, 2, 4, 6, 8 }, { 1, 3, 5, 7, 9 } };
for(int i=0; i<2;i++)
{
for (int j = 0; j < 5; j++)
{
Console.Write("\t"+arr[i,j]);
}
Console.WriteLine("\n\t");
}
Console.WriteLine("\n\nArray 2 Data\n");
int[,] arr1 = new int[2,3];
arr1[0, 0] = 11;
arr1[0, 1] = 22;
arr1[0, 2] = 33;
arr1[1, 0] = 10;
arr1[1, 1] = 20;
arr1[1, 2] = 30;