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
Post a Comment