Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of

Inheriting from CollectionBase

The first step necessary to implement a strongly typed collection is to define a class that generalizes CollectionBase. (You also can inherit from ReadOnlyCollectionBase, to implement a read-only version of the strongly typed collection.) Listing 1 demonstrates how to inherit from the CollectionBase class; we'll assume that we're defining a beer selection collection for a bar franchise, perhaps "Pauly's".

Listing 1—Inherit from System.Collections.CollectionBase to Create a Strongly Typed Collection

public class BeerInventory : System.Collections.CollectionBase

Listing 1 demonstrates the basic syntax for expressing an inheritance relationship. (The same syntax is used when you want to implement an interface.)

  • + Share This
  • 🔖 Save To Your Account