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

51,876 answers

573 users

How to initialize two dimensional int array in C#

2 Answers

0 votes
using System;
   
class Program
{
    static void Main() {
        int[,] array2d = { { 4, 6 }, 
                           { 5, 7 },
                           { 0, 1 }, 
                           { 9, 12 },
                           { 8, 16 }, 
                           { 69, 98 } };
                            
        Console.WriteLine(array2d.GetLength(0));                                   
        Console.WriteLine(array2d.GetLength(1));                           
   
        for (int i = 0; i < array2d.GetLength(0); i++) {
            for (int j = 0; j < array2d.GetLength(1); j++) {
                Console.Write("{0} ", array2d[i, j]);
            }
            Console.WriteLine();
        }
    }
}
   
   
   
   
/*
run:
   
6
2
4 6 
5 7 
0 1 
9 12 
8 16 
69 98 
   
*/

 



answered Nov 25, 2020 by avibootz
edited Nov 26, 2020 by avibootz
0 votes
using System;
  
class Program
{
    static void Main() {
        int [,] array2d = new int [4, 3] { { 4, 6, 7}, 
                                           { 0, 1, 3}, 
                                           { 9, 12, 18},
                                           { 69, 32, 98} };
                           
        Console.WriteLine(array2d.GetLength(0));                                   
        Console.WriteLine(array2d.GetLength(1));                           
  
        for (int i = 0; i < array2d.GetLength(0); i++) {
            for (int j = 0; j < array2d.GetLength(1); j++) {
                Console.Write("{0} ", array2d[i, j]);
            }
            Console.WriteLine();
        }
    }
}
  
  
  
  
/*
run:
  
4
3
4 6 7 
0 1 3 
9 12 18 
69 32 98 
  
*/

 



answered Nov 26, 2020 by avibootz

Related questions

1 answer 110 views
1 answer 155 views
4 answers 300 views
...