C# 为什么没有静态索引器?
可能的重复项:C# 为什么没有静态索引器?,c#,static-indexers,C#,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&l
目前,我必须这样编写代码
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