C# Programming - Arrays - Discussion
Discussion Forum : 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}};
- intMyArr represents rectangular array of 2 rows and 3 columns.
- intMyArr.GetUpperBound(1) will yield 2.
- intMyArr.Length will yield 24.
- intMyArr represents 1-D array of 5 integers.
- intMyArr.GetUpperBound(0) will yield 2.
Discussion:
10 comments Page 1 of 1.
Mahesh said:
2 years ago
Option:1 Correct because the dimensions are 2 rows and 3 columns.
Options:2 Correct because the upper bound in the array means the first element in an array of the mentioned index.
As intMyArry. GetUpperBound (0) means intMyArray[1][0].
Options:2 Correct because the upper bound in the array means the first element in an array of the mentioned index.
As intMyArry. GetUpperBound (0) means intMyArray[1][0].
(2)
Moses said:
1 decade ago
1 even to I give 100% correct.
(1)
Rv2137 said:
10 years ago
Everyone wrong please explain correct answer.
(1)
Mariya said:
5 years ago
Hi,
Please share the answer.
If int[, ,]a={3,2,3}.
Then what is the length of a?
Please share the answer.
If int[, ,]a={3,2,3}.
Then what is the length of a?
(1)
Supragaya said:
1 decade ago
int[ , ] intMyArr = this gives us idea of getting a two dimensional matrix.
So ans 1 is right.
So ans 1 is right.
Nitish Jha said:
1 decade ago
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.
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:
1 decade ago
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:
1 decade ago
@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:
1 decade ago
Yes first one is the right answer. Because array declared as a second array.
Karthi said:
9 years ago
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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers