• Home
  •  Single Dimensional Array

 Single Dimensional Array

Agenda

Array in C#

1) Declaring the Array – Example: int [] intArray;

2) Constructing the Array – Example: intArray = new int[4];

3) Initialize the Array – Example: intArray[0] = 1; intArray[1] = 4; intArray[2] = 3; intArray[3] = 2;

Array in C# - Contd.


  [] intArray;
intArray = new int[4];
intArray[0] = 1; intArray[1] = 4; intArray[2] = 3; intArray[3] = 2;
intArray[0] = 5;
Console.WriteLine(intArray[3]);
Console.WriteLine(intArray.Length);
for (int i = 0; i < intArray.Length; i++)
Console.WriteLine(intArray[i]);

//Array.Sort(intArray);

foreach (int i in intArray)
{
Console.WriteLine(i);
}

Console.WriteLine(intArray.Max());
Console.WriteLine(intArray.Min());
Console.WriteLine(intArray.Sum());
Console.WriteLine(intArray.Average());

Array.Reverse(intArray);

string[] cars = { "Maruti", "BMW", "Honda", "Hyundai" }; Array.Sort(cars);

foreach (string s in cars)
{
Console.WriteLine(s);
}