Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Array, List, HashSet, and Dictionary are just four of the many collection types provided by the System.Collections.Generic namespace.
-
0:00
Array, list, hashSet and dictionary can get us a long ways, but
-
0:05
there are many other types of collections.
-
0:07
All of them have specific advantages.
-
0:10
It's important to always pick the correct collection for
-
0:12
the way the data is being used.
-
0:15
The four collections we've learned about so
-
0:16
far may not always be the best for the job.
-
0:20
Let's briefly look at some of the other less common collection
-
0:24
types provided by the .NET Framework.
-
0:27
We'll start in the System.Collections.Generic namespace.
-
0:30
Here we see another list collection.
-
0:34
It's called LinkedList.
-
0:36
LinkedList is different than the list collection type we used earlier in
-
0:39
this course.
-
0:41
Linked lists are used when we want to be able to quickly add or
-
0:44
remove items without the items in the list being shifted.
-
0:48
This works because linked lists don't use an array internally.
-
0:52
Instead it's a list of individual nodes that are linked to each other.
-
0:56
They're much faster at adding and removing items than an array based list.
-
1:00
On the other hand, linked list don't provide a quick way to index
-
1:03
directly into items in the list using an index.
-
1:06
A queue is like a list except items can only be added to the end of the queue and
-
1:11
they can only be removed from the beginning.
-
1:14
This is why it's called a first in first out or FIFO collection type.
-
1:19
You can think of this just like the line at a grocery store.
-
1:22
The first person in the line is the first person that checks out.
-
1:26
A stack on the other hand is a last in, first out or LIFO collection.
-
1:31
With the stack we can only add and remove items from one end of the stack.
-
1:35
Think of this like a stack of plates.
-
1:38
The last plate, placed on the top of the stack,
-
1:41
is the first one that'll be used when we need a plate.
-
1:44
Queues and stacks are limited in the types of operations we can do with them, but
-
1:47
these limitations allow them to be very efficient at storing and retrieving data.
-
1:52
They're commonly used to simplify how algorithms for
-
1:55
processing data are implemented.
-
1:57
Then we have a number of sorted collection types.
-
2:00
A sortedSet doesn't use an object's hash code to determine if it's in the set.
-
2:05
Instead it keeps the items in the set sorted, so they're arranged in
-
2:09
such a way that it can quickly determine if an item is in the set.
-
2:12
Just like hashSet, it also doesn't allow duplicates.
-
2:16
SortedDictionary works just like a sorted set,
-
2:19
where the keys of the dictionary are sorted.
-
2:21
As with tne normal dictionary, a value can be associated with each key.
-
2:25
SortedSet and sortedDictionary take up less additional memory than hashSet and
-
2:29
the standard dictionary, especially when the number of items becomes large.
-
2:34
And of course they should be used if we want to loop through the items or
-
2:38
keys in a sorted order.
-
2:40
SortedList is actually more like a dictionary than it is a list.
-
2:45
As you can see, it contains both keys and values.
-
2:49
Just like sortedDictionary, the keys of a sorted list are stored in sorted order.
-
2:54
It uses less memory than a sorted dictionary but it's also slower adding and
-
2:59
removing items.
You need to sign up for Treehouse in order to download course files.
Sign up