创建字典<string,Dictionary <T,T []> []>

fur*_*kle 3 .net c#

在C#中,实例化和初始化包含字典数组值的字典的语法是什么,那些字典本身包含数组作为值?

例如,(我相信),

Dictionary<string, Dictionary<string, string[]>[]>?
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试做的一个例子:

private static readonly Dictionary<string, Dictionary<string, DirectoryInfo[]>[]> OrderTypeToFulfillmentDict = new Dictionary<string, Dictionary<string, DirectoryInfo[]>>()
    {
        {"Type1", new [] 
                { 
                    ProductsInfo.Type1FulfillmentNoSurfacesLocations, 
                    ProductsInfo.Type2FulfillmentSurfacesLocations 
                } 
        }
    }
Run Code Online (Sandbox Code Playgroud)

其中Type1Fulfillment ...和Type2Fulfillment ...已构造为

Dictionary<string, DirectoryInfo[]>. 
Run Code Online (Sandbox Code Playgroud)

这会引发以下编译器错误:

"Cannot convert from System.Collections.Generic.Dictionary<string, System.IO.DirectoryInfo[]>[] to System.Collections.Generic.Dictionary<string, System.IO.DirectoryInfo[]>"
Run Code Online (Sandbox Code Playgroud)

编辑:问题是,正如Lanorkin指出的那样,我错过[]了新的决赛Dictionary<string, Dictionary<string, DirectoryInfo[]>>().不过,不言而喻,这可能不是任何人应该首先尝试做的事情.

Sea*_*ean 5

你所拥有的东西看起来是正确的,但是你正在做的事情有一个真正的代码味道,这将导致一些严重的技术债务.

对于初学者而言,不是Dictionary<string, string[]>在类中使用内部模型,而是使用适合您要建模的方法.否则,任何访问此类型的人都不会知道它真正建模的内容.