MCQs on Arrays and Collections | C#

Chapter 6 explores arrays and collections in C#, covering fundamental concepts such as arrays, multidimensional arrays, jagged arrays, and key collection types like List, Dictionary, Queue, and Stack for efficient data handling.


Multiple Choice Questions (MCQs)

Section 1: Arrays in C#

  1. In C#, how do you define an array of integers with 5 elements?
    a) int[] arr = new int(5);
    b) int arr = new int[5];
    c) int[] arr = {1, 2, 3, 4, 5};
    d) int[] arr = new int[] {1, 2, 3, 4, 5};
  2. What is the default value of an uninitialized integer array element in C#?
    a) 0
    b) null
    c) 1
    d) NaN
  3. Which of the following methods is used to determine the length of an array in C#?
    a) Length()
    b) Count()
    c) array.Length
    d) array.Count()
  4. How do you access the third element of an array arr in C#?
    a) arr[2]
    b) arr[3]
    c) arr[1]
    d) arr[0]
  5. Which of the following is correct for initializing an array in C#?
    a) int arr = {1, 2, 3, 4};
    b) int arr[4] = {1, 2, 3, 4};
    c) int[] arr = {1, 2, 3, 4};
    d) int[] arr = new int[] {1, 2, 3, 4};
  6. What is the correct way to iterate through an array in C#?
    a) foreach(int item in arr) { Console.WriteLine(item); }
    b) for (int i = 0; i < arr.length; i++) { Console.WriteLine(arr[i]); }
    c) for each arr { Console.WriteLine(arr); }
    d) for (int item in arr) { Console.WriteLine(item); }

Section 2: Multidimensional Arrays

  1. How do you declare a two-dimensional array in C#?
    a) int[2][2] arr;
    b) int[,] arr = new int[2, 2];
    c) int[2,2] arr = new int[2, 2];
    d) int[][] arr = new int[2, 2];
  2. How do you access an element in a two-dimensional array arr at row 1, column 2?
    a) arr[1][2]
    b) arr[1, 2]
    c) arr(1, 2)
    d) arr[2, 1]
  3. What will be the result of the following code?
    int[,] arr = new int[3, 3]; arr[1, 1] = 5; Console.WriteLine(arr[1, 1]);
    a) 3
    b) 1
    c) 5
    d) 0
  4. Can multidimensional arrays in C# be jagged?
    a) Yes
    b) No
    c) Only for 1D arrays
    d) Only for 2D arrays
  5. What is the maximum number of dimensions supported in C# for an array?
    a) 2
    b) 3
    c) 4
    d) 32
  6. Which of the following is a valid initialization of a 3×3 matrix in C#?
    a) int[,] matrix = new int[3][3];
    b) int[3, 3] matrix = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
    c) int[,] matrix = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    d) int[3, 3] matrix = new int[3, 3];

Section 3: Jagged Arrays

  1. What is a jagged array in C#?
    a) An array of arrays
    b) An array with fixed dimensions
    c) An array of strings
    d) An array with a single element
  2. How do you declare a jagged array in C#?
    a) int[2][] arr;
    b) int[][] arr = new int[2][];
    c) int[2][2] arr;
    d) int[] arr[2];
  3. In a jagged array, can each sub-array have a different length?
    a) Yes
    b) No
    c) Only for multidimensional arrays
    d) Only for arrays with one dimension
  4. What will be the output of the following code?
    int[][] jaggedArray = new int[2][]; jaggedArray[0] = new int[3]; jaggedArray[1] = new int[4]; Console.WriteLine(jaggedArray[0].Length);
    a) 4
    b) 3
    c) 2
    d) 5
  5. How do you initialize a jagged array with specific values in C#?
    a) int[][] arr = new int[] { {1, 2}, {3, 4} };
    b) int[][] arr = new int[2] {1, 2, 3, 4};
    c) int[][] arr = new int[2][] { new int[] {1, 2}, new int[] {3, 4} };
    d) int arr[][] = { {1, 2}, {3, 4} };
  6. How would you print the first element of a jagged array arr?
    a) Console.WriteLine(arr[0][0]);
    b) Console.WriteLine(arr[0]);
    c) Console.WriteLine(arr[1][0]);
    d) Console.WriteLine(arr[0]);

Section 4: Collections (List, Dictionary, Queue, Stack)

  1. What type of collection is List<T> in C#?
    a) Fixed-size collection
    b) Dynamic-size collection
    c) Ordered collection
    d) Unordered collection
  2. How do you add an item to a List<int> in C#?
    a) list.Add(10);
    b) list.Insert(10);
    c) list[0] = 10;
    d) list.Append(10);
  3. What is the key feature of a Dictionary<TKey, TValue> in C#?
    a) It stores elements in a sorted order
    b) It uses key-value pairs
    c) It supports duplicate keys
    d) It stores elements in a linear list
  4. Which method is used to retrieve an element by key from a Dictionary in C#?
    a) dictionary.GetValue(key);
    b) dictionary[key];
    c) dictionary.Get(key);
    d) dictionary.Lookup(key);
  5. What type of collection is Queue<T> in C#?
    a) First In, Last Out
    b) Last In, First Out
    c) FIFO (First In, First Out)
    d) Unordered
  6. How do you add an element to a Queue<T> in C#?
    a) queue.Enqueue(value);
    b) queue.Push(value);
    c) queue.Add(value);
    d) queue.Insert(value);
  7. Which method removes and returns the first element from a Queue in C#?
    a) queue.Pop();
    b) queue.Dequeue();
    c) queue.Remove();
    d) queue.Delete();
  8. What type of collection is Stack<T> in C#?
    a) FIFO (First In, First Out)
    b) LIFO (Last In, First Out)
    c) Queue
    d) Dictionary
  9. How do you add an item to a Stack<T> in C#?
    a) stack.Push(value);
    b) stack.Enqueue(value);
    c) stack.Add(value);
    d) stack.Insert(value);
  10. How do you remove the top item from a Stack in C#?
    a) stack.Dequeue();
    b) stack.Pop();
    c) stack.Remove();
    d) stack.Delete();
  11. Which of the following is true about the List<T> in C#?
    a) It supports dynamic resizing
    b) It does not allow null elements
    c) It does not maintain element order
    d) It is slower than an array for accessing elements
  12. Which collection is best suited for storing data that needs to be accessed in a first-come, first-served manner?
    a) List
    b) Queue
    c) Stack
    d) Dictionary

Answer Key

QnoAnswer
1d) int[] arr = new int[] {1, 2, 3, 4, 5};
2a) 0
3c) array.Length
4a) arr[2]
5c) int[] arr = {1, 2, 3, 4};
6a) foreach(int item in arr) { Console.WriteLine(item); }
7b) int[,] arr = new int[2, 2];
8b) arr[1, 2]
9c) 5
10a) Yes
11d) 32
12b) int[,] matrix = {1, 2, 3, 4, 5, 6, 7, 8, 9};
13a) An array of arrays
14b) int[][] arr = new int[2][];
15a) Yes
16b) 3
17c) int[][] arr = new int[2][] { new int[] {1, 2}, new int[] {3, 4} };
18a) Console.WriteLine(arr[0][0]);
19b) Dynamic-size collection
20a) list.Add(10);
21b) It uses key-value pairs
22b) dictionary[key];
23c) FIFO (First In, First Out)
24a) queue.Enqueue(value);
25b) queue.Dequeue();
26b) LIFO (Last In, First Out)
27a) stack.Push(value);
28b) stack.Pop();
29a) It supports dynamic resizing
30b) Queue

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top