Q:

C# program to print the lower bound and upper bound of an array

belongs to collection: C# Basic Programs | array programs

0

C# program to print the lower bound and upper bound of an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to print the lower bound and upper bound of an array in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to print the lower bound 
//and upper bound of an array in C#

using System;

class Program
{
    static void Main(string[] args)
    {
        Array intArray = Array.CreateInstance(typeof(int), 5);
        
        intArray.SetValue(10, 0);
        intArray.SetValue(20, 1);
        intArray.SetValue(30, 2);
        intArray.SetValue(40, 3);
        intArray.SetValue(50, 4);
        
        Console.WriteLine("Lower Bound : "+intArray.GetLowerBound(0));
        Console.WriteLine("Upper Bound : " + intArray.GetUpperBound(0));
    }
}

Output:

Lower Bound : 0
Upper Bound : 4
Press any key to continue . . .

Explanation:

In the above program, we created an array of integers using Array class and then set some values using SetValue() method and then get the lower and upper bound using GetLowerBound() and GetUpperBound() method. The lower bound of array specifies the lowest index of the array and upper bound specifies the highest index of the array.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | array programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to find out the dimensions of an array... >>
<< C# program to demonstrate the example of LongLengt...