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,895 questions

51,826 answers

573 users

How to use Array.GetLength() method to get number of elements in the specified dimension of an Array in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Array arr1D = Array.CreateInstance(typeof(int), 7);

            Console.WriteLine(arr1D.GetLength(0));
        }
    }
}


/*
run:
 
7

*/

 



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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Array arr2D = Array.CreateInstance(typeof(int), 6, 3);

            Console.WriteLine("dimension[0] = {0}", arr2D.GetLength(0));
            Console.WriteLine("dimension[1] = {0}", arr2D.GetLength(1));
        }
    }
}


/*
run:
  
dimension[0] = 6
dimension[1] = 3
 
*/

 



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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Array arr3D = Array.CreateInstance(typeof(int), 6, 4, 3);

            Console.WriteLine("dimension[0] = {0}", arr3D.GetLength(0));
            Console.WriteLine("dimension[1] = {0}", arr3D.GetLength(1));
            Console.WriteLine("dimension[2] = {0}", arr3D.GetLength(2));
        }
    }
}


/*
run:
 
dimension[0] = 6
dimension[1] = 4
dimension[2] = 3

*/

 



answered Apr 24, 2016 by avibootz
...