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