4

IGrouping & lt; Int, Keypair & gt; int; To the dictionary

 3 years ago
source link: https://www.codesd.com/item/igrouping-int-keypair-int-to-the-dictionary.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

IGrouping & lt; Int, Keypair & gt; int; To the dictionary

advertisements

I seperated my main dictonary into a group of multiple dictonaries so that I can shoot threads off with the smaller set of dictonaries.

Here is the code that seperates my main Dictonary into multiple smaller ones:

int numberOfGroups = 10;
int counter = 0;
var result = offenderWorkload.GroupBy(x => counter++ % numberOfGroups);

Now I am having trouble to obtain one dictonary from the set of 10 within the result.

I need to seperate result into 10 different dictonaries and shoot off threads so something like...

foreach(var something in result)
{
    Dictionary<String, int> workLoad = (Dictionary<String, int>)something.ToDictionary();
    Console.WriteLine("workload: " + something.Key + " has " + workLoad.Keys.Count);
}

So that something is keypair that gets casted to a dictonary and ignoring the int in the Igroup.


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

Because after group by, each grouping member is not a dictionary, but a collection of KeyValuePair's.

Tags dictionary

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK