在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[]>>().不过,不言而喻,这可能不是任何人应该首先尝试做的事情.