C# Program to Print the Lower Bound and Upper Bound of an Array

This is a C# Program to get lower bound and upper bound of an array.

Problem Description

This C# Program Gets Lower Bound and Upper Bound of an Array.

Problem Solution

Here The GetLowerBound and GetUppperBound methods return the lower and upper bounds of an array respectively.

Program/Source Code

Here is source code of the C# Program to Get Lower Bound and Upper Bound of an Array. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program Gets Lower Bound and Upper Bound of an Array
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lower
{
    class Program
    {
        static void Main(string[] args)
        {
            Array stringArray = Array.CreateInstance(typeof(String), 6);
            stringArray.SetValue("Mango", 0);
            stringArray.SetValue("Orange", 1);
            stringArray.SetValue("Apple", 2);
            stringArray.SetValue("Grape", 3);
            stringArray.SetValue("Cherry", 4);
            stringArray.SetValue("WaterMelon", 4);
            Console.WriteLine("The Lower Bound of the Array : {0}",
                              stringArray.GetLowerBound(0).ToString());
            Console.WriteLine("The Upper Bound of the Array : {0}",
                              stringArray.GetUpperBound(0).ToString());
            Console.ReadLine();
 
        }
    }
}
Program Explanation

In this C# program, using setvalue() function create an object for string Array. For loop is used assign the coefficient element values of an array. Here the GetLowerBound and GetUppperBound methods return the lower and upper bounds of an array respectively. Print the lower bound and upper bound of an array.

advertisement
advertisement
Runtime Test Cases
 
The Lower Bound of the Array : 0
The Upper Bound of the Array : 5

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.