Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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语言列表词典(似乎无法获取我的列表)_C#_Linq_List_Collections - Fatal编程技术网

C# c语言列表词典(似乎无法获取我的列表)

C# c语言列表词典(似乎无法获取我的列表),c#,linq,list,collections,C#,Linq,List,Collections,在这里,我使用linq过滤数组中的结果,并将其传递到列表中,然后从该列表中传递到字典中,如下面所示 //array is a multidimensional array with string data in it var datumn = array; var list = new List<string>(); var stringcounts = new Dictionary<int,List<string>>(); var listtemp = n

在这里,我使用linq过滤数组中的结果,并将其传递到列表中,然后从该列表中传递到字典中,如下面所示

//array is a multidimensional array with string data in it 
var datumn = array;
var list = new List<string>();
var stringcounts = new Dictionary<int,List<string>>();
var listtemp = new List<string>();

//linq

var arrayresult = from string a in datumn where a != "FREE" select a;

//adding result from arrayresult to list

foreach (var listing in arrayresult)
{
    list.Add(listing);
}

//using linq again i filter my list then add to dictionary

for (int count = 3; count > 0; count-- )
{
    var duplicateItems = from x in list
                         group x by x into grouped
                         where grouped.Count() == count 
                         select grouped.Key;
    foreach (var replace in duplicateItems)
    {
        listtemp.Add(replace.ToString());
    }

    stringcounts.Add(count, lists);

    //clearing the list to avoid duplicating data in my dictionary 
    listtemp.Clear();

}

for (int key = stringcounts.Count; key > 0; --key)
{
    var holding = stringcounts[key];

    foreach (var li in holding)
    {
        MessageBox.Show(li.ToString());
        //just view what i have to check if the data is correct
    }

}
` 该程序跳过列表的迭代器,并结束有人可以帮助的列表 我尝试了一切,包括linq和其他集合,比如hashtable 和映射,但没有任何功能,它不是控制台应用程序

这一行是错误的:

   var dict = new Dictionary<int, List<string>>();
卸下

结果:

靛蓝银紫紫绿粉红红棕黄

编辑:用于比较的完整代码:

   var dict = new Dictionary<int, List<string>>()
  {
 {1, new List<string>{"red", "brown", "yellow"}},
 {2, new List<string>{"purple", "green", "pink"}},
 {3, new List<string>{"indigo", "silver", "violet"}}        
  };

// now i want to get my values from the lists in the dictionary 

for (int count = 3; count > 0; count--)
{
    var l = dict[count];

    foreach (var li in l)
    {
        li.Dump();
    }
}

listtemp.Clear是一个错误的语法,因此应该删除它,并且应该在for循环中声明listtemp,因此删除冗余和初始问题

我不知道问题出在哪里。我自己不是英语母语的人,但我知道你应该用任何人都能理解的方式来表达你的问题。@KamilT如果你能发现我的错误,现在就看一看,因为我不能:?@Carra在上面看一看我试图缩短到无法工作的整个代码:?ryt naw程序读取键值,因为我刚刚对其进行了检查,但值本身(即列表)未显示在显示器上。我已使用linqpad对其进行了测试,替换了消息。显示为转储。它应该起作用@卡拉,我想我应该发布我的全部代码,这样你就可以看到它有什么问题了,因为它已经好几天了
foreach (var item in dict)
        {
            var list = item.Value;
            foreach (var str in list)
            {
                MessageBox.Show(str);
            }
        }