【发布时间】:2009-06-01 18:28:58
【问题描述】:
可能的重复:
How to reference an indexer member of a class in C# comments
Static Indexers?
就目前而言,我必须像这样编写我的代码
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();
}
并访问索引:
Type t = ReportMap.Instance[aChar]; // eww
这种能力被排除在语言之外是否有特定的原因?特别是,它会被认为是糟糕的设计吗?对此已经发布了另一个问题,但不幸的是,我没有足够的代表发表评论。
【问题讨论】:
-
我认为这个问题在stackoverflow.com/questions/401232/static-indexers得到了回答
标签: c# static-indexers