C# Programming - Arrays - Discussion

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

1. 

Which of the following statements are correct about the C#.NET code snippet given below?

int[ , ] intMyArr = {{7, 1, 3}, {2, 9, 6}};
  1. intMyArr represents rectangular array of 2 rows and 3 columns.
  2. intMyArr.GetUpperBound(1) will yield 2.
  3. intMyArr.Length will yield 24.
  4. intMyArr represents 1-D array of 5 integers.
  5. intMyArr.GetUpperBound(0) will yield 2.

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

Answer: Option A

Explanation:

No answer description available for this question.

Supragaya said: (Sep 18, 2011)  
int[ , ] intMyArr = this gives us idea of getting a two dimensional matrix.

So ans 1 is right.

Nitish Jha said: (Nov 19, 2012)  
By examining syntax of this array it is clear that - this is a 2-D array with 2 rows and 3 columns.
GetUpperBound(0) returns the upper bound for the indexes of the first dimension of the Array, and GetUpperBound(1) returns the upper bound of the last dimension of the Array.

Natasha said: (Jan 10, 2014)  
How intMyArr.GetUpperBound(1) will yield 2. the output of this statement should be 7 how come it is 2. It is represents rectangular array of 2 rows and 3 columns.

Zia Ul Murtaza said: (Apr 20, 2014)  
@Natasha, It will yield 2 because there are two rows in this two dimensional array. Index starts from 0 so intMyArr.GetUpperBound(0) will yield upper bound 1 and intMyArr.GetUpperBound(1) will yield upper bound 2.

Nithin Tn said: (May 27, 2015)  
Yes first one is the right answer. Because array declared as a second array.

Moses said: (Aug 21, 2015)  
1 even to I give 100% correct.

Rv2137 said: (Sep 2, 2015)  
Everyone wrong please explain correct answer.

Karthi said: (Dec 25, 2016)  
int[ , ] z = {{7, 1, 3}, {2, 9, 6}};

Console.WriteLine("Rank (Dimensions)1 UP {0} LOW {1} Rank 2 UP {2} LOW {3}",z.GetUpperBound(0),z.GetLowerBound(0),z.GetUpperBound(1),z.GetLowerBound(1));

GetUpperBound => Returns index of the last element of the specified dimension in the array.
GetLowerBound => Returns index of the first element of the specified dimension in the array.

Output:
Rank (Dimensions)1 UP 1 LOW 0 Rank 2 UP 2 LOW 0.

Mariya said: (Jun 8, 2020)  
Hi,
Please share the answer.

If int[, ,]a={3,2,3}.
Then what is the length of a?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.