C# Programming - Arrays - Discussion

Discussion Forum : Arrays - General Questions (Q.No. 14)
14.
Which of the following is the correct way to obtain the number of elements present in the array given below?
    int[] intMyArr = {25, 30, 45, 15, 60};
  1. intMyArr.GetMax;
  2. intMyArr.Highest(0);
  3. intMyArr.GetUpperBound(0);
  4. intMyArr.Length;
  5. intMyArr.GetMaxElements(0);
1, 2
3, 4
3, 5
1, 5
4, 5
Answer: Option
Explanation:
using System;
    
public class Test
{ 
   public static void Main()
   { 
        int[] intMyArr = { 25, 30, 45, 15, 60, 78, 99 };
        Console.WriteLine(intMyArr.Length);
        Console.WriteLine(intMyArr.GetUpperBound(0)+1);
   } 
}
/* 
Output : 
7 
7 
*/
Discussion:
1 comments Page 1 of 1.

IRSHAD said:   1 decade ago
intMyArr.GetUpperBound(0);

Won't give the correct count of number of elements in the array. But will only give 1 less than the count.

Post your comments here:

Your comments will be displayed after verification.