Chapter 7: Stepping through Collections

In This Chapter

check.png Handling a directory as a collection of files and a file as a collection of bytes

check.png “Enumerating,” or iterating, a collection

check.png Implementing an indexer for easy access to collection objects

check.png Easily looping through a collection with the C# iterator blocks

Chapter 6 in this minibook explores the collection classes provided by the .NET Framework class library for use with C# and other .NET languages. Collection classes are constructs in .NET that can be instantiated to hold groups of items (see Chapter 6).

The first part of this chapter extends the notion of collections a bit. For instance, consider the following collections: a file as a collection of lines or records of data, and a directory as a collection of files. Thus, this chapter builds on both the collection material in Chapter 6 of this minibook and the file material in Book III.

However, the focus in this chapter is on several ways to step through, or iterate, all sorts of collections, from file directories to arrays and lists of all sorts.

Iterating through a Directory ...

Get C# 5.0 All-in-One For Dummies now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.