Collections

A collection class refers to a class that represents a collection of similar objects. For example, you can create a MyBookCollection class that manages a collection of objects of the Books class. The MyBookCollection class provides a number of methods to modify the collection. Some of these methods are Add(), Clear(), Insert(), and Remove().

The MyBookCollection class is shown in Listing 8.20.

Listing 8.20. The MyBookCollection Class
 using System; using System.Collections; public class Books { string name; public Books(string t) { name=t; } public string DispValue() { return name; } } public class MyBookCollection : IEnumerable { private Books []BookCollection; Books b1,b2,b3; public MyBookCollection() { b1=new Books(“Gone With ...

Get Special Edition Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.