Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

How to use GetUpperBound() and GetLowerBound() methods to get the upper and lower bound of an array in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            int upper = arr.GetUpperBound(0);
            int lower = arr.GetLowerBound(0);
            Console.WriteLine("index from: {0} to: {1}", lower, upper);
        }
    }
}


/*
run:
   
index from: 0 to: 9
  
*/

 



answered Apr 25, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] arr2D = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, 
                             { 9, 10 }, { 11, 12 }, { 13, 14 } };

            for (int i = 0; i < arr2D.Rank; i++)
                Console.WriteLine("Dimension {0}: index from {1} to {2}",
                                  i, arr2D.GetLowerBound(i),
                                  arr2D.GetUpperBound(i));
        }
    }
}


/*
run:
   
Dimension 0: index from 0 to 6
Dimension 1: index from 0 to 1
  
*/

 



answered Apr 25, 2016 by avibootz

Related questions

1 answer 169 views
169 views asked Aug 28, 2020 by avibootz
1 answer 187 views
1 answer 192 views
...