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

Array indexing and access in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this array access code?

Consider the following C# code snippet. What will be printed to the console?

C Sharp (C#)
int[] numbers = {10, 20, 30, 40, 50};
Console.WriteLine(numbers[2]);
A20
B10
C30
D40
Attempts:
2 left
💡 Hint

Remember, array indexing in C# starts at 0.

Predict Output
intermediate
2:00remaining
What happens when accessing an invalid array index?

What will happen when this code runs?

C Sharp (C#)
int[] values = {1, 2, 3};
Console.WriteLine(values[3]);
APrints 3
BThrows IndexOutOfRangeException
CPrints 0
DPrints null
Attempts:
2 left
💡 Hint

Check what happens if you try to access an index outside the array bounds.

Predict Output
advanced
2:00remaining
What is the output of this multidimensional array access?

Given the code below, what will be printed?

C Sharp (C#)
int[,] matrix = { {1, 2}, {3, 4} };
Console.WriteLine(matrix[1, 0]);
A3
B2
C1
D4
Attempts:
2 left
💡 Hint

Remember the first index is the row, the second is the column.

Predict Output
advanced
2:00remaining
What is the output of this jagged array access?

What will this code print?

C Sharp (C#)
int[][] jagged = new int[][] {
    new int[] {1, 2},
    new int[] {3, 4, 5}
};
Console.WriteLine(jagged[1][2]);
A5
B3
C4
D2
Attempts:
2 left
💡 Hint

Jagged arrays are arrays of arrays. Access the second array, then its third element.

Predict Output
expert
2:00remaining
What is the output of this code with negative indexing attempt?

What will happen when this code runs?

C Sharp (C#)
int[] arr = {100, 200, 300};
Console.WriteLine(arr[-1]);
APrints 300
BPrints -1
CPrints 100
DThrows IndexOutOfRangeException
Attempts:
2 left
💡 Hint

Check if C# supports negative indexes for arrays.