Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么没有静态索引器?_C#_Static Indexers - Fatal编程技术网

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