Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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# i分组<;int,密钥对>;查字典_C#_Dictionary - Fatal编程技术网

C# i分组<;int,密钥对>;查字典

C# i分组<;int,密钥对>;查字典,c#,dictionary,C#,Dictionary,我把我的主要口述材料分成了一组多个口述材料,这样我就可以用一组较小的口述材料来表达我的想法 下面是将我的主要口述词分为多个小口述词的代码: int numberOfGroups = 10; int counter = 0; var result = offenderWorkload.GroupBy(x => counter++ % numberOfGroups); 现在我很难从结果中的10组中获得一个口述词 我需要把结果分成10个不同的录音带,然后放出一些线索,比如 foreach(va

我把我的主要口述材料分成了一组多个口述材料,这样我就可以用一组较小的口述材料来表达我的想法

下面是将我的主要口述词分为多个小口述词的代码:

int numberOfGroups = 10;
int counter = 0;
var result = offenderWorkload.GroupBy(x => counter++ % numberOfGroups);
现在我很难从结果中的10组中获得一个口述词

我需要把结果分成10个不同的录音带,然后放出一些线索,比如

foreach(var something in result)
{
    Dictionary<String, int> workLoad = (Dictionary<String, int>)something.ToDictionary();
    Console.WriteLine("workload: " + something.Key + " has " + workLoad.Keys.Count);
}
foreach(结果中的变量)
{
字典工作量=(Dictionary)something.ToDictionary();
WriteLine(“工作负载:+something.Key+”具有“+workload.Keys.Count”);
}
因此,某个东西是键对,它被强制转换为听写式,并忽略Igroup中的int

Dictionary工作负载=something.ToDictionary(x=>x.Key,x=>x.Value);
Dictionary<String, int> workLoad = something.ToDictionary(x => x.Key, x => x.Value);

因为在group by之后,每个分组成员不是字典,而是KeyValuePair的集合。

这将为您提供一组字典。每个字典都有
n
元素

int n = (int)Math.Ceiling((double)offenderWorkload.Count/numberOfGroups);

IEnumerable<Dictionary<string, int>> result =
    offenderWorkload.GroupBy(x => counter++/n)
        .Select(x => x.ToDictionary(d => d.Key, d => d.Value));

你的问题是什么?我想他想把他的字典分成几个部分,这样他就可以平衡工作量了。我不认为GroupBy是你要找的。如果我的假设是正确的,您是否尝试过创建自己的分区方法?签名将是公共静态列表分区(Dictionary Dictionary,int maxCountPerPartition);或公共静态列表分区(字典、整数分区);
int numberOfGroups = 10;
int counter = 0;
int n = (int)Math.Ceiling((double)offenderWorkload.Count/numberOfGroups);

var result =
    offenderWorkload.GroupBy(x => counter++/n)
        .Select(x => x.ToDictionary(d => d.Key, d => d.Value));

int i = 0;
foreach (var workLoad in result)
{
    Console.WriteLine("workload: " + i++ + " has " + workLoad.Keys.Count);
}