C#中的多维关联数组

Get*_*awn 1 c# arrays list arraylist

我试图找到一些我可以拥有一个包含键/值列表的键/值列表的东西,所以它看起来像这样:

String Item 1
    +- key1 -> Object
    +- key2 -> Object
String Item 2
    +- key1 -> Object
    +- key2 -> Object
    +- key3 -> Object
    +- key4 -> Object
String Item 3
    +- key1 -> Object
Run Code Online (Sandbox Code Playgroud)

在PHP它看起来像这样:

array(
    "String Item 1" => array(
        "key1" => Object,
        "key2" => Object
    ),
    "String Item 2" => array(
        "key1" => Object,
        "key2" => Object,
        "key3" => Object,
        "key4" => Object
    ),
    "String Item 3" => array(
        "key1" => Object
    )
);
Run Code Online (Sandbox Code Playgroud)

在C#中有什么可以做的吗?

Far*_*ina 10

您可以使用使用通用字典作为值的通用字典:

var dict = new Dictionary<string, Dictionary<string, object>>();

// Adding a value
dict.Add("key", new Dictionary<string, object>()
{
    { "key1", "value1" },
    { "key2", "value2" }
});

// Retrieving value1
var result = dict["key"]["key1"];
Run Code Online (Sandbox Code Playgroud)