Indexers Are Also Inherited and Can Be Overridden
Even though Chapter 14, “Class Anatomy III: Writing Intuitive Code,” told us that indexers do not carry a name, like its method and property siblings, but instead are called by referring to an object name followed by a pair of square brackets enclosing an indexer, they are still inherited and can be overridden like methods and properties. Listing 16.5 demonstrates how an indexer can be overridden and also introduces a new use for the base keyword (other than when used as part of the constructor initializer discussed earlier), which allows you to call the indexer of a base class.
Listing 16.5. SeasonalAdjustment.cs
01: using System; 02: 03: class ProductionList 04: { 05: private uint[] production ... |
Get C# Primer Plus 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.