15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10<br />

Collec tions<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Underst<strong>and</strong>ing collection interfaces <strong>and</strong> types<br />

Working with lists, queues, <strong>and</strong> stacks<br />

Working with linked <strong>and</strong> sorted lists<br />

Using dictionaries <strong>and</strong> sets<br />

Using bit arrays <strong>and</strong> bit vectors<br />

Evaluating performance<br />

In Chapter 6, “ Arrays <strong>and</strong> Tuples, ” you read about arrays <strong>and</strong> the interfaces implemented by the<br />

Array class. The size of arrays is fi xed. If the number of elements is dynamic, you should use a collection<br />

class.<br />

List < T > is a collection class that can be compared to arrays. But there are also other kinds of collections:<br />

queues, stacks, linked lists, <strong>and</strong> dictionaries.<br />

Version 1 of the .<strong>NET</strong> Framework included non - generic collection classes such as<br />

ArrayList <strong>and</strong> HashTable . CLR 2.0 added support for generics <strong>and</strong> generic collection<br />

classes. The focus of this chapter is on the newer group of collection classes <strong>and</strong> mainly<br />

ignores the old ones, as they are rarely needed with new applications.<br />

ColleCTion inTerfaCes <strong>and</strong> TyPes<br />

Most collection classes can be found in the System.Collections <strong>and</strong> System.Collections.<br />

Generic namespaces. Generic collection classes are located in the System.Collections<br />

.Generic namespace. Collection classes that are specialized for a specifi c type are located in the<br />

System.Collections.Specialized namespace. Thread - safe collection classes are in the System.<br />

Collections.Concurrent namespace.<br />

Of course, there are also other ways to group collection classes. Collections can be grouped into lists,<br />

collections, <strong>and</strong> dictionaries based on the interfaces that are implemented by the collection class.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!