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

51,791 answers

573 users

How to find the length (rows, cols) of 2D array in C#

4 Answers

0 votes
using System;

class Program
{
    static void Main() {
        int[,] array2d = new int[2, 3] { { 1, 8, 5 }, 
                                         { 6, 7, 1 } };
                                           
        int rows = array2d.GetUpperBound(0) + 1;
        int cols = array2d.GetUpperBound(1) + 1;

        Console.WriteLine(rows);
        Console.WriteLine(cols);
    }
}




 
/*
run:
 
2
3
 
*/

 



answered Mar 1, 2016 by avibootz
edited Aug 10, 2023 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        int[,] array2d = { { 1,   2,   3,   6,  0},
                           {-5,  -4,   0,   7,  9},
                           { 1,   7, 100,  14,  6},
                           { 9,  10,  11,  12, 13} };
         

        int rows = array2d.GetUpperBound(0) + 1;
        int cols = array2d.GetUpperBound(1) + 1;

        Console.WriteLine(rows);
        Console.WriteLine(cols);
    }
}




 
/*
run:
 
4
5
 
*/

 



answered Mar 1, 2016 by avibootz
edited Aug 10, 2023 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        int[,] array2d = { { 1,   2,   3,   6,  0},
                           {-5,  -4,   0,   7,  9},
                           { 1,   7, 100,  14,  6},
                           { 9,  10,  11,  12, 13} };
         

        int rows = array2d.GetLength(0);
        int cols = array2d.GetLength(1);

        Console.WriteLine(rows);
        Console.WriteLine(cols);
    }
}




 
/*
run:
 
4
5
 
*/

 



answered Aug 10, 2023 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        int[,] array2d = new int[2, 3] { { 1, 8, 5 }, 
                                         { 6, 7, 1 } };
                                           
        int rows = array2d.GetLength(0);
        int cols = array2d.GetLength(1);

        Console.WriteLine(rows);
        Console.WriteLine(cols);
    }
}




 
/*
run:
 
2
3
 
*/

 



answered Aug 10, 2023 by avibootz

Related questions

1 answer 206 views
4 answers 390 views
2 answers 254 views
2 answers 272 views
1 answer 230 views
...