Classes and Objects in C#
15 questions · 12 min · Medium
Test your knowledge of arrays in C# with 15 questions covering array declaration, initialization, indexing, iteration, multidimensional arrays, properties, and common array operations.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. int[] numbers;
In C#, an array can be declared by placing square brackets after the type, such as int[] numbers.
A. int[] numbers = new int[5];
The new int[5] expression creates an integer array with five elements.
A. 0
C# arrays are zero-indexed, so the first element is at index 0.
B. 10
Array indexing starts at 0, so numbers[0] refers to the first element, which is 10.
C. Length
The Length property returns the total number of elements in an array.
C. An IndexOutOfRangeException is thrown
Accessing an array with an invalid index causes an IndexOutOfRangeException at runtime.
A. foreach
The foreach loop provides a simple way to iterate through each element of an array.
C. 0
Elements of a newly created int array are initialized to the default value of int, which is 0.
A. int[] numbers = { 10, 20, 30 };
C# supports array initializer syntax using curly braces to specify the initial elements.
B. int[,] matrix;
A comma inside the brackets declares a rectangular two-dimensional array in C#.
A. matrix[1, 2]
C# rectangular multidimensional arrays use comma-separated indexes inside a single pair of brackets.
A. Array.Sort()
The static Array.Sort() method can sort the elements of an array.
B. Reverses the order of elements in the array
Array.Reverse() reverses the sequence of elements in the specified array.
B. A jagged array is an array whose elements are themselves arrays
A jagged array is an array of arrays, allowing each inner array to have a different length.
A. int[][] numbers = new int[2][];
The syntax int[][] creates a jagged array, and new int[2][] creates space for two inner arrays.