• Tutorials
  • Courses
  • Tracks

C#: Collections - Lists and Dictionaries Quiz

Last Updated :
Discuss
Comments

Question 1

Which of the following statements about List<T> in C# is true?

  • List<T> cannot contain duplicate elements

  • List<T> is always sorted by default

  • List<T> allows null values for reference types

  • List<T> has a fixed capacity and cannot grow

Question 2

What is the default initial capacity of an ArrayList in C#?

  • 0

  • 2

  • 4

  • 8

Question 3

What is the main difference between List<T> and ArrayList in C#?

  • ArrayList allows duplicates while List<T> does not

  • List<T> is generic while ArrayList is non-generic

  • List<T> is always sorted while ArrayList is not

  • ArrayList has fixed size while List<T> is dynamic

Question 4

Which methods are used to check the existence of keys and values in a C# Dictionary?

  • ContainsKey() and ContainsValue()

  • HasKey() and HasValue()

  • ExistsKey() and ExistsValue()

  • CheckKey() and CheckValue()

Question 5

Which method is used to copy all elements of a Collection<T> to an array?

  • Clone()

  • Copy()

  • CopyTo()

  • Export()

Question 6

Which property of Collection<T> is used to access an element by index?

  • Items

  • ElementAt

  • Item[Int32]

  • GetAt(Int32)

Question 7

Which statement is correct about collection initializers in C#?

  • They replace the Add() method internally

  • They cannot contain null values

  • They only work with arrays

  • They require at least one constructor argument

Question 8

Which constructor creates a list with a specified initial capacity?

  • List<T>()

  • List<T>(IEnumerable<T>)

  • List<T>(Int32)

  • List<T>(Capacity<T>)

Question 9

What is the main advantage of using an object initializer in C#?

  • It replaces constructors completely

  • It initializes object properties directly at creation

  • It automatically sorts object properties

  • It prevents null values in objects

Question 10

Which property of the Collection<T> class is used to retrieve the number of elements contained in the collection?

  • Items

  • Count

  • Length

  • Capacity

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion