15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

266 ❘ ChaPTer 10 cOllectiOns<br />

(continued)<br />

ColleCTion add tnserT remoVe iTem torT find<br />

Dictionary<br />

<br />

SortedDictionary<br />

<br />

SortedList<br />

<br />

O(1) or O(n) na O(1) O(1) na na<br />

O(log n) na O(log n) O(log n) na na<br />

O(n) for<br />

unsorted<br />

data, O(log n)<br />

for end of list,<br />

O(n) if resize<br />

is needed<br />

na O(n) O(log n) to<br />

read/ write,<br />

O(log n) if<br />

the key is in<br />

the list, O(n)<br />

if the key is<br />

not in the list<br />

na<br />

na<br />

summary<br />

This chapter took a look at working with different kinds of collections. Arrays are fixed in size, but you can<br />

use lists for dynamically growing collections. For accessing elements on a first-in, first-out basis, there’s a<br />

queue, <strong>and</strong> there’s a stack for last-in, first-out operations. Linked lists allow for fast inserting <strong>and</strong> removing<br />

of elements but are slow for searching. With keys <strong>and</strong> value, you can use dictionaries, which are fast<br />

for searching <strong>and</strong> inserting elements. Sets are for unique items <strong>and</strong> can be ordered (SortedSet) or not<br />

ordered (HashSet). ObservableCollection gives events when items change in the list.<br />

In this chapter, you’ve seen a lot of interfaces <strong>and</strong> classes <strong>and</strong> their use for accessing <strong>and</strong> sorting collections.<br />

You’ve also seen some specialized collections, such as BitArray <strong>and</strong> BitVector32, which are optimized for<br />

working with a collection of bits.<br />

Chapter 11 gives you details about Language Integrated Query (LINQ).<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!