c# - Best way to enumerate all combinations -
suppose have following list in order:
s1 r1 r2 s2 s3 i need create list each "s" contains each "r" combination
output:
s1 => r1 s1 => r2 s2 => r1 s2 => r2 s3 => r1 s3 => r2 what's best way achieve this? thanks
try:
var byprefix = list.groupby(i => i.first()).todictionary(g => g.key, g => g); var result = s in byprefix['s'] r in byprefix['r'] select new { s, r };
Comments
Post a Comment