Home »
Aptitude Questions and Answers »
C# Aptitude Questions and Answers
C# Arrays Aptitude Questions and Answers | Set 4
C# Arrays Aptitude Questions | Set 4: This section contains aptitude questions and answers on C# Arrays.
Submitted by Nidhi, on April 01, 2020
1) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.GetLength(1));
}
- 5
- 6
- Syntax Error
- Runtime Error
Correct answer: 4
Runtime Error
The above code will generate runtime exception.
2) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.GetLength(0));
}
- 5
- 6
- Syntax Error
- Runtime Error
Correct answer: 1
5
The above code will print length of created array.
3) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
Console.WriteLine(ARR.MAX());
}
- 5
- 6
- Syntax Error
- Runtime Error
Correct answer: 3
Syntax Error
The above code will generate syntax error, because MAX() method is not available.
4) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[] ARR = {1,2,3,4,5};
int X = 0;
int i = 0;
X = ARR[0];
for (i = 1; i < ARR.Length; i++)
{
if (X < ARR[i])
X = ARR[i];
}
Console.WriteLine(X);
}
- 5
- 6
- Syntax Error
- Runtime Error
Correct answer: 1
5
The above code will print greatest value of array.
5) What is the correct output of given code snippets?
static void Main(string[] args)
{
int[,] ARR = {{1,2},{3,4}};
Console.WriteLine(ARR.GetLength(1));
}
- 5
- 2
- Syntax Error
- Runtime Error
Correct answer: 2
2
The GetLength(1) method will print specified number of elements in the dimensions.