Skip to content
QuiznExam

Collection Classes in C#

Test your knowledge of collection classes in C#, including ArrayList, Hashtable, List, Dictionary, Queue, Stack, and other collection concepts.

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 namespace contains many of the non-generic collection classes in C#?

    • A. System.Collections
    • B. System.Collections.Generic
    • C. System.CollectionClasses
    • D. System.Data.Collections
    Show answer

    A. System.Collections

    The System.Collections namespace contains non-generic collection classes such as ArrayList, Hashtable, Queue, and Stack.

  2. 2. Which generic collection is commonly used to store a strongly typed list of elements?

    • A. Hashtable
    • B. ArrayList
    • C. List<T>
    • D. Queue
    Show answer

    C. List<T>

    List<T> is a generic collection that stores elements of a specified type and provides strongly typed access.

  3. 3. Which collection stores elements as key-value pairs?

    • A. List<T>
    • B. Dictionary<TKey, TValue>
    • C. Stack<T>
    • D. Queue<T>
    Show answer

    B. Dictionary<TKey, TValue>

    Dictionary<TKey, TValue> stores values using unique keys that are associated with each value.

  4. 4. Which collection follows the First-In-First-Out (FIFO) principle?

    • A. Stack<T>
    • B. Queue<T>
    • C. Dictionary<TKey, TValue>
    • D. HashSet<T>
    Show answer

    B. Queue<T>

    A Queue<T> follows FIFO, meaning the first element added is normally the first element removed.

  5. 5. Which collection follows the Last-In-First-Out (LIFO) principle?

    • A. Queue<T>
    • B. List<T>
    • C. Stack<T>
    • D. Dictionary<TKey, TValue>
    Show answer

    C. Stack<T>

    A Stack<T> follows LIFO, meaning the most recently added element is normally the first one removed.

  6. 6. Which non-generic collection can store elements of different types and is found in System.Collections?

    • A. List<T>
    • B. ArrayList
    • C. Dictionary<TKey, TValue>
    • D. HashSet<T>
    Show answer

    B. ArrayList

    ArrayList is a non-generic collection that can store objects of different types. Generic collections are generally preferred for type safety.

  7. 7. Which collection is designed to store unique elements?

    • A. HashSet<T>
    • B. List<T>
    • C. Queue<T>
    • D. Stack<T>
    Show answer

    A. HashSet<T>

    HashSet<T> is designed to store unique elements and does not allow duplicate elements according to its equality comparer.

  8. 8. Which method adds an element to a List<T>?

    • A. InsertItem()
    • B. Add()
    • C. Push()
    • D. Enqueue()
    Show answer

    B. Add()

    The Add() method appends an element to a List<T>.

  9. 9. Which method adds an element to a Queue<T>?

    • A. Push()
    • B. Add()
    • C. Enqueue()
    • D. Insert()
    Show answer

    C. Enqueue()

    Enqueue() adds an element to the end of a Queue<T>.

  10. 10. Which method adds an element to a Stack<T>?

    • A. Push()
    • B. Enqueue()
    • C. Add()
    • D. Append()
    Show answer

    A. Push()

    Push() adds an element to the top of a Stack<T>.

  11. 11. Which method removes and returns the element at the front of a Queue<T>?

    • A. Pop()
    • B. Remove()
    • C. Dequeue()
    • D. Delete()
    Show answer

    C. Dequeue()

    Dequeue() removes and returns the element at the beginning of a Queue<T>.

  12. 12. Which method removes and returns the top element of a Stack<T>?

    • A. Dequeue()
    • B. Pop()
    • C. Remove()
    • D. Take()
    Show answer

    B. Pop()

    Pop() removes and returns the element at the top of a Stack<T>.

  13. 13. What is a major advantage of generic collections such as List<T> over older non-generic collections such as ArrayList?

    • A. They cannot contain objects
    • B. They provide compile-time type safety
    • C. They can only store strings
    • D. They do not support iteration
    Show answer

    B. They provide compile-time type safety

    Generic collections specify the element type, reducing invalid type assignments and avoiding many unnecessary casts.

  14. 14. Which collection is commonly used to map unique keys to values?

    • A. Dictionary<TKey, TValue>
    • B. Stack<T>
    • C. Queue<T>
    • D. List<T>
    Show answer

    A. Dictionary<TKey, TValue>

    Dictionary<TKey, TValue> provides a key-value mapping where each key must be unique within the dictionary.

  15. 15. Which interface is commonly implemented by collections that can be enumerated using foreach?

    • A. IEnumerable
    • B. IDisposable
    • C. IComparable
    • D. IFormattable
    Show answer

    A. IEnumerable

    IEnumerable provides the basic mechanism for obtaining an enumerator, allowing a collection to be traversed with foreach.