Skip to content
QuiznExam

Arrays in C# Quiz – 15 Questions with Answers

Test your knowledge of arrays in C# with 15 questions covering array declaration, initialization, indexing, iteration, multidimensional arrays, properties, and common array operations.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which syntax correctly declares an integer array in C#?

    • A. int numbers[];
    • B. int[] numbers;
    • C. array int numbers;
    • D. int numbers = array;
    Show answer

    B. int[] numbers;

    In C#, an array can be declared by placing square brackets after the type, such as int[] numbers.

  2. 2. Which statement correctly creates an integer array containing five elements?

    • A. int[] numbers = new int[5];
    • B. int numbers = new int(5);
    • C. int[] numbers = int[5];
    • D. array<int> numbers = 5;
    Show answer

    A. int[] numbers = new int[5];

    The new int[5] expression creates an integer array with five elements.

  3. 3. What is the index of the first element in a C# array?

    • A. 0
    • B. 1
    • C. -1
    • D. It depends on the array
    Show answer

    A. 0

    C# arrays are zero-indexed, so the first element is at index 0.

  4. 4. What is the value of numbers[0] in the following code? int[] numbers = { 10, 20, 30 };

    • A. 0
    • B. 10
    • C. 20
    • D. 30
    Show answer

    B. 10

    Array indexing starts at 0, so numbers[0] refers to the first element, which is 10.

  5. 5. Which property returns the total number of elements in a C# array?

    • A. Size
    • B. Count
    • C. Length
    • D. Elements
    Show answer

    C. Length

    The Length property returns the total number of elements in an array.

  6. 6. What happens if you try to access an array element using an index outside its valid range?

    • A. The value becomes null
    • B. The array automatically expands
    • C. An IndexOutOfRangeException is thrown
    • D. The program always returns 0
    Show answer

    C. An IndexOutOfRangeException is thrown

    Accessing an array with an invalid index causes an IndexOutOfRangeException at runtime.

  7. 7. Which loop is commonly used to iterate through every element of an array without manually managing an index?

    • A. foreach
    • B. switch
    • C. goto
    • D. lock
    Show answer

    A. foreach

    The foreach loop provides a simple way to iterate through each element of an array.

  8. 8. What is the default value of the elements in a newly created int array?

    • A. 1
    • B. -1
    • C. 0
    • D. null
    Show answer

    C. 0

    Elements of a newly created int array are initialized to the default value of int, which is 0.

  9. 9. Which statement correctly initializes an array with three integer values?

    • A. int[] numbers = { 10, 20, 30 };
    • B. int[] numbers = (10, 20, 30);
    • C. int numbers[] = (10, 20, 30);
    • D. array numbers = [10, 20, 30];
    Show answer

    A. int[] numbers = { 10, 20, 30 };

    C# supports array initializer syntax using curly braces to specify the initial elements.

  10. 10. Which syntax declares a two-dimensional integer array in C#?

    • A. int[][] matrix;
    • B. int[,] matrix;
    • C. int<> matrix;
    • D. int[2] matrix;
    Show answer

    B. int[,] matrix;

    A comma inside the brackets declares a rectangular two-dimensional array in C#.

  11. 11. Which expression accesses the element in row 1 and column 2 of a two-dimensional array named matrix?

    • A. matrix[1, 2]
    • B. matrix(1, 2)
    • C. matrix[1][2]
    • D. matrix{1, 2}
    Show answer

    A. matrix[1, 2]

    C# rectangular multidimensional arrays use comma-separated indexes inside a single pair of brackets.

  12. 12. Which method can be used to sort the elements of an array?

    • A. Array.Sort()
    • B. Array.Order()
    • C. Array.Arrange()
    • D. Array.Sorting()
    Show answer

    A. Array.Sort()

    The static Array.Sort() method can sort the elements of an array.

  13. 13. What does Array.Reverse() do?

    • A. Deletes the array
    • B. Reverses the order of elements in the array
    • C. Sorts the array in ascending order
    • D. Creates a copy with the same order
    Show answer

    B. Reverses the order of elements in the array

    Array.Reverse() reverses the sequence of elements in the specified array.

  14. 14. What is the main difference between a rectangular multidimensional array and a jagged array in C#?

    • A. A rectangular array can contain only strings
    • B. A jagged array is an array whose elements are themselves arrays
    • C. A jagged array cannot store integers
    • D. There is no difference
    Show answer

    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.

  15. 15. Which statement correctly creates a jagged array with two inner arrays?

    • A. int[][] numbers = new int[2][];
    • B. int[,] numbers = new int[2][];
    • C. int[2][] numbers = new int[][];
    • D. int[][] numbers = new int[,2];
    Show answer

    A. int[][] numbers = new int[2][];

    The syntax int[][] creates a jagged array, and new int[2][] creates space for two inner arrays.