Data Collections Flashcards

1
Q

What is the primary purpose of data collections in C# .Net?

A

To store and manage groups of related data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Arrays in C# are fixed in size after they are created.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: The __________ collection is used for storing key-value pairs.

A

Dictionary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

List<T> is dynamic in size while Array is fixed in size.</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which data collection type would you use for a collection that requires unique elements?

A

HashSet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What interface do all collection types in C# implement?

A

IEnumerable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: A Queue in C# follows a Last In First Out (LIFO) order.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What collection type is best suited for implementing a stack in C#?

A

Stack<T>.</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the ‘T’ represent in List<T>?</T>

A

Type parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which collection allows duplicates and maintains the order of elements?

A

List<T>.</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the primary use of the ConcurrentBag<T> collection?</T>

A

To store a collection of objects that can be accessed by multiple threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Fill in the blank: A __________ is a collection that can be accessed in a thread-safe manner.

A

Concurrent collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What collection type would you use for a first-in, first-out (FIFO) access pattern?

A

Queue<T>.</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: The Dictionary<TKey, TValue> collection allows duplicate keys.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What method is used to add an element to a List<T>?</T>

A

Add().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which collection type is best for implementing a lookup table?

A

Dictionary<TKey, TValue>.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the default capacity of a List<T> when it is created?</T>

A

0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

True or False: A LinkedList<T> allows access to elements by index.</T>

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the time complexity of accessing an element in a List<T> by index?</T>

20
Q

What collection would you use to store a fixed-size collection of objects?

21
Q

Fill in the blank: The __________ class provides a way to store a collection of objects in a sorted order.

A

SortedList.

22
Q

What is the primary advantage of using a HashSet?

A

It provides fast lookup times for unique elements.

23
Q

Which method removes all elements from a collection in C#?

24
Q

True or False: A Stack<T> allows random access to elements.</T>

25
What is the purpose of the IEnumerable interface?
It allows iteration over a collection.
26
Which collection type is ideal for storing items with a unique identifier?
Dictionary.
27
Fill in the blank: The __________ method is used to sort elements in a List.
Sort().
28
What collection type can automatically resize itself as elements are added?
List.
29
True or False: The ArrayList class is type-safe.
False.
30
What does the 'Contains' method do in a collection?
It checks if a specific element is present in the collection.
31
Which collection is best suited for implementing a priority queue?
SortedSet.
32
What is the time complexity of adding an element to a HashSet?
O(1) on average.
33
True or False: You can use the foreach loop to iterate over a List.
True.
34
What collection would you use for a collection of objects that need to be ordered but can contain duplicates?
List.
35
Fill in the blank: The __________ class is designed for storing data in a key-value pair format.
Dictionary.
36
What is a key characteristic of the Queue collection?
It follows FIFO order.
37
Which collection type is best for scenarios involving frequent additions and removals?
LinkedList.
38
True or False: A Dictionary can be iterated using a foreach loop.
True.
39
What method would you use to find the index of an element in a List?
IndexOf().
40
What does the 'AddRange' method do in a List?
It adds multiple elements to the List at once.
41
Which collection type is not designed for concurrent access?
List.
42
Fill in the blank: The __________ class is a generic collection that stores elements in a sorted order.
SortedSet.
43
What is the primary use of the ObservableCollection?
To provide notifications when items are added, removed, or the entire list is refreshed.
44
True or False: The List class implements the IList interface.
True.
45
What collection would you choose for a simple list of items with no specific order?
List.