c# - Split dictionary into multiple equal sized dictionaries -


i have dictionary shown below. there 400 elements in dictionary want split dictionary 4 equal sized dictionaries. how do this? list there range method can use not sure here?

i not care how dictionary split equally sized.

dictionary<string, companydetails> codic; 

you can use simple modulus group dictionary in parts:

int numberofgroups = 4; int counter = 0;  var result = dict.groupby(x => counter++ % numberofgroups); 

the modulus (%) makes groupby restricted number in range 0..3 (actually 0..numberofgroups - 1). make grouping you.

a problem though 1 doesn't preserve order. 1 does:

decimal numberofgroups = 4; int counter = 0; int groupsize = convert.toint32(math.ceiling(dict.count / numberofgroups));  var result = dict.groupby(x => counter++ / groupsize); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -