November 2001
Beginner to intermediate
816 pages
16h 3m
English
Indexers are overloaded similar to methods. By providing different numbers and types of parameters, indexers can be very flexible. Listing 9.2 shows an example of indexer overloading.
using System; public enum Month { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec } public enum Category { Food, Home, Jeans, Fun } public class Budget { decimal[,] myBudget = new decimal[4, 12]; public void Initialize(decimal[] initVals) { for (Category c=Category.Food; c <= Category.Fun; c++) { for (Month m=Month.Jan; m <= Month.Dec; m++) { myBudget[(int)c, (int)m] = initVals[(int)m]; } } } public void Initialize(decimal initVal) { for (Category c=Category.Food; c <= Category.Fun; c++) { for (Month ... |
Read now
Unlock full access