C# Program for Function of Array (Simple Example)




using System;
class Program {
static void Main(string[] args) {
string[] strArray = { "str1", "str2", "str3", "str4", "str5" };//Array index {0},{1} {2} {3} {4}
int lower = strArray.GetLowerBound(0);//we get 1st index no. that is {0}
int upper = strArray.GetUpperBound(0);//we get last index no. that is {4}
int length = strArray.Length;
Console.WriteLine("ntstring[] strArray = {"str1","str2","str3","str4","str5"};n");
Console.WriteLine("tLowerBound = {0} //strArray[{1}] holds the value "{2}"n",lower,lower,strArray[lower]);
Console.WriteLine("tUpperBound = {0} //strArray[{1}] holds the value "{2}"n", upper, upper, strArray[upper]);
Console.WriteLine("tArray length = {0} // i.e., there are five total elements (elements 0,1,2,3, and 4)n", length);
Console.WriteLine("To exit program, press the Enter key… ");
Console.ReadLine();
}
}

Output : 

Previous Post Next Post