C# Programming - Arrays - Discussion

Discussion :: Arrays - General Questions (Q.No.9)

9. 

Which of the following are the correct ways to define an array of 2 rows and 3 columns?

  1. int[ , ] a;
    a = new int[2, 3]{{7, 1, 3},{2, 9, 6}};
  2. int[ , ] a;
    a = new int[2, 3]{};
  3. int[ , ] a = {{7, 1, 3}, {2, 9,6 }};
  4. int[ , ] a;
    a = new int[1, 2];
  5. int[ , ] a;
    a = new int[1, 2]{{7, 1, 3}, {2, 9, 6}};

[A]. 1, 2 , 3
[B]. 1, 3
[C]. 2, 3
[D]. 2, 4, 5
[E]. 4, 5

Answer: Option B

Explanation:

No answer description available for this question.

Nik said: (Nov 11, 2014)  
Can any one tell me how it is correct answer?

Thanks in advance.

Samir said: (Oct 26, 2015)  
int[ , ] a;

a = new int[2, 3]{{7, 1, 3},{2, 9, 6}};

Here [2,3] 2 rows and 3 column and initialize also done there .


int[ , ] a = {{7, 1, 3}, {2, 9,6 }};

Here initialize done here in 1st row 3 element and 2nd row 3.

Sayali said: (Mar 12, 2016)  
Why 2nd option is wrong?

Vinothkumar said: (Jun 16, 2017)  
I think braces will not be empty because it contains array elements.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.