C# Collections Fundamentals Flashcards

1
Q

What are Collections?

A
  • collections manage groups of objects in memory
  • collections are generic
  • objects in collections referred to as Elements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are 3 types of Collections?

A
  • Lists - good for memory use, efficient at accessing elements, usually zero based indexed
  • Dictionaries - access elements using a key, most are implemented under covers using a hash table, generally list w/ index have perf edge of dict with key
  • Sets - collections designed to combine to form new collections… unions, intersections, etc, not meant to lookup individual elements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an Array?

A
  • arrays have always been strongly typed in .NET 1.0
  • index based lists
  • rich API, special synctax, very lightweight
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why are Array sizes fixed?

A
  • when initialized Arrays hold a certain block of memory
  • accessing items by index just counts bytes and positions in that memory block
  • to expand array, no guarantee that neighboring block of memory would be available
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Arrays - for loop vs foreach loop?

A
  • for an array the for and foreach are essentially same
  • foreach does for loop under the covers
  • for arrays, item in foreach is readonly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly