Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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#列表<&燃气轮机;将列表添加到字典 Dictionary SetPiese=newdictionary(); char[]litere=“ABCDEFGHIJLMNOPRSTUVXZ”.ToCharArray(); 对于(int i=1;i_C# - Fatal编程技术网

C#列表<&燃气轮机;将列表添加到字典 Dictionary SetPiese=newdictionary(); char[]litere=“ABCDEFGHIJLMNOPRSTUVXZ”.ToCharArray(); 对于(int i=1;i

C#列表<&燃气轮机;将列表添加到字典 Dictionary SetPiese=newdictionary(); char[]litere=“ABCDEFGHIJLMNOPRSTUVXZ”.ToCharArray(); 对于(int i=1;i,c#,C#,我想这是可行的: Dictionary<string, List<Piese>> SetPiese = new Dictionary<string, List<Piese>>(); char[] litere = "ABCDEFGHIJLMNOPRSTUVXZ".ToCharArray(); for (int i = 1; i <= litere.Length; i++) {

我想这是可行的:

        Dictionary<string, List<Piese>> SetPiese = new Dictionary<string, List<Piese>>();

        char[] litere = "ABCDEFGHIJLMNOPRSTUVXZ".ToCharArray();

        for (int i = 1; i <= litere.Length; i++) {
            SetPiese.Add(litere[i], Set + litere[i]);
        }

        List<Piese> SetA = GenerareSetLitere("A", 1, 11);
        List<Piese> SetB = GenerareSetLitere("B", 9, 2);
        List<Piese> SetC = GenerareSetLitere("C", 1, 5);
        ................................................
Dictionary SetPiese=newdictionary();
List SetA=一般集合(“A”,1,11);
List SetB=一般集合(“B”,9,2);
List SetC=一般集合(“C”,1,5);
添加(“A”,SetA);
加上(“B”,立根);
添加(“C”,SetC);

我不确定,因为您没有提到字典的键。

非常简单,不要在单独的变量中声明它们。以编程方式处理它们总是一件痛苦的事情。如果您从以下方面开始:

Dictionary<string, List<Piese>> SetPiese = new Dictionary<string, List<Piese>>();
List<Piese> SetA = GenerareSetLitere("A", 1, 11);
List<Piese> SetB = GenerareSetLitere("B", 9, 2);
List<Piese> SetC = GenerareSetLitere("C", 1, 5);
SetPiese.Add("A", SetA);
SetPiese.Add("B", SetB);
SetPiese.Add("C", SetC);

等。

是的,它是有效的,但如果我有3个以上的列表?你不能…做SetPiese.Add(“ABCDE..XYZ”,Set[ABCDEF…XYZ]);26次:)@Jon Skeet得到了:)谢谢。@AppDeveloper:请不要对无关的问题或答案添加评论。
List<Piese>[] sets = new List<Piese>[]
{
    GenerareSetLitere("A", 1, 11),
    GenerareSetLitere("B", 9, 2),
    GenerareSetLitere("C", 1, 5)
    ...
};
// Note loop condition change
for (int i = 0; i < litere.Length; i++) {
    SetPiese.Add(litere[i], sets[i]);
}
Dictionary<string, List<Piese>> SetPiese = new Dictionary<string, List<Piese>>
{
    { "first-key", GenerareSetLitere("A", 1, 11) },
    { "second-key", GenerareSetLitere("B", 9, 2) }
};