0
0
C Sharp (C#)programming~20 mins

Single-dimensional array declaration in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of array length after declaration
What is the output of this C# code snippet?
C Sharp (C#)
int[] numbers = new int[5];
Console.WriteLine(numbers.Length);
A5
B0
C6
DCompilation error
Attempts:
2 left
💡 Hint
Remember that the Length property returns the number of elements in the array.
Predict Output
intermediate
2:00remaining
Value of array element after declaration
What is the output of this C# code snippet?
C Sharp (C#)
int[] values = new int[3];
Console.WriteLine(values[1]);
A1
B0
Cnull
DIndexOutOfRangeException
Attempts:
2 left
💡 Hint
Default values for int elements in a new array are important here.
Predict Output
advanced
2:00remaining
Output of array initialization with values
What is the output of this C# code snippet?
C Sharp (C#)
string[] fruits = new string[] {"apple", "banana", "cherry"};
Console.WriteLine(fruits[2]);
Aapple
Bbanana
Ccherry
Dnull
Attempts:
2 left
💡 Hint
Array indexing starts at zero.
Predict Output
advanced
2:00remaining
Error type when accessing invalid index
What error does this C# code produce when run?
C Sharp (C#)
int[] arr = new int[2];
Console.WriteLine(arr[3]);
ANo error, prints 0
BNullReferenceException
CArgumentOutOfRangeException
DIndexOutOfRangeException
Attempts:
2 left
💡 Hint
Accessing an index outside the array bounds causes a runtime error.
🧠 Conceptual
expert
2:00remaining
Number of elements in a declared array
How many elements does the array contain after this declaration in C#?
double[] data = new double[10];
A10
B9
C11
D0
Attempts:
2 left
💡 Hint
The number inside the brackets specifies the array size.