I need to split my dictionary using LINQ expression. I need to split into two parts. Could somebody help me?
var myDictionary = new Dictionary<int, int>();
var halfOfDictionary = myDictionary.ToDictionary(...)
I need to split my dictionary using LINQ expression. I need to split into two parts. Could somebody help me?
var myDictionary = new Dictionary<int, int>();
var halfOfDictionary = myDictionary.ToDictionary(...)
// remove OrderBy if ordering is not important
var ordered = dictionary.OrderBy(kv => kv.Key);
var half = dictionary.Count/2;
var firstHalf = ordered.Take(half).ToDictionary(kv => kv.Key, kv => kv.Value);
var secondHalf = ordered.Skip(half).ToDictionary(kv => kv.Key, kv => kv.Value);