Collection Base Example

Collection classes can be a convenient method to handling sets of data. In many cases, collections handle strong types better than other classes within the .NET framework. There are several different ways to implement a collection class. This blog entry demonstrates how easy it is to implement a collection class by inheriting the CollectionBase class.

This demonstration creates a collection of line items for an amortization schedule. 

The input of the amortization schedule is the following:

  • Starting Balance 
  • Periodic Payment Amount
  • Periodic Interest Rate

The output will be the following in a set of data:

  • The Current Period Count
  • The Period's Starting Balance
  • The Period's Interest Amount Paid
  • The Period's Principal Amount Paid
  • The Period's Ending Balance 
The following is output of the program further illustrating what a amortization schedule does.
 

In C#, inheritance is simple. Here is the class declaration used to create the collection class: 

class Amortization : CollectionBase 

Although not implemented in this case, there methods that can be overridden to handle the indexing of the collection of amortization periods. I have chosen to hide these methods as this collection is read-only and its data is generated by the program only.

Source code is available to download. Give it a whirl.

CollectionExample.zip (28.17 kb)