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

Here, we are going to learn how to print the lower bound and upper bound of an array in C#?
Submitted by Nidhi, on August 22, 2020

Here we create an integer array get the lower and upper bound of the array. The lower bound of array specifies the lowest index of the array and upper bound specifies the highest index of the array.

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.