Chapter 7. Stepping through Collections

In This Chapter

  • Handling a directory as a collection of files and a file as a collection of bytes

  • Implementing a LinkedList collection

  • "Enumerating," or iterating, LinkedList

  • Implementing an indexer for easy access to collection objects

  • 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. As you probably remember, collection classes are constructs in .NET that can be instantiated to hold groups of items. If you don't remember, you can read Chapter 6 for a reminder.

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. You also see how to write your own collection class, or linked list.

Iterating through a Directory of Files

Reading and writing are the basic skills you need to get ahead in this world. That's what makes the FileRead and FileWrite programs in Book IV important. In some cases, however, you simply want to skim a directory of files, looking for ...

Get C# 2010 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.