Call GetLength for two dimenional array : Array Dimension : Collections Data Structure C# Source Code


Custom Search

C# Source Code » Collections Data Structure » Array Dimension »

 

Call GetLength for two dimenional array








    
 

using System;

class ChessBoard {
    static void Main(String[] args) {
        Char[,] SquareColor = new Char[8, 8];
        for (int i = 0; i < SquareColor.GetLength(0); i++) {
            for (int x = 0; x < SquareColor.GetLength(1); x++) {
                if ((x % 2) == 0)
                    if ((i % 2) == 0)
                        SquareColor[i, x] = 'W';
                    else
                        SquareColor[i, x] = 'B';
                else
                    if ((i % 2) == 0)
                        SquareColor[i, x] = 'B';
                    else
                        SquareColor[i, x] = 'W';
            }
        }

        for (int i = 0; i < SquareColor.GetLength(0); i++) {
            for (int x = 0; x < SquareColor.GetLength(1); x++) {
                Console.Write(SquareColor[i, x]);
            }
            Console.WriteLine();
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» Array Dimension