0

Possible Duplicates:
How to reference an indexer member of a class in C# comments
Static Indexers?


As it stands, I have to write my code like this

internal class ReportMap {

    static internal ReportMap Instance {
        get { return reportMap; }
    }

    internal Type this[char c] {
        get { return data[c]; }
    }

    // private parts
    static Dictionary<char, Type> data =
        new Dictionary<char, Type>();

    ReportMap() {
        data.Add('S', typeof(StatusReport));
        data.Add('Q', typeof(QualityReport));
    }

    static ReportMap reportMap = new ReportMap();
}

and to access an index:

Type t = ReportMap.Instance[aChar]; // eww

Is there a specific reason this ability was left out of the language? In particular, would it be considered bad design? There is another question on this already posted, but I unfortunately do not have enough rep to comment.

Community
  • 1
  • 1
xofz
  • 5,600
  • 6
  • 45
  • 63

1 Answers1

0

That's a good dupe reference there. Specifically, check out the answer :-) Static Indexers?

Community
  • 1
  • 1
Joel Martinez
  • 46,929
  • 26
  • 130
  • 185