How to get the rows and columns of a matrix (2D array) in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[,] arr = {     
                        {1, 2, 3, 5},  
                        {4, 5, 6, 5},  
                        {7, 8, 9, 5}  
                    };  
            
        int rows = arr.GetLength(0);  
        int cols = arr.GetLength(1); 
        
        Console.WriteLine("rows = " + rows); 
        Console.WriteLine("cols = " + cols); 
    }
}




/*
run:

rows = 3
cols = 4

*/

 



answered Feb 20, 2021 by avibootz

Related questions

2 answers 232 views
1 answer 227 views
1 answer 252 views
2 answers 238 views
1 answer 183 views
...