c# - IEnumerable<T> to IDictionary<U, IEnumerable<T>> -
what's efficient way convert ienumerable<t>
idictionary<u, ienumerable<t>>
where u is, example guid, information held in property of t.
basically, creates dictionary of lists items in original list grouped based on value in property within objects.
example
object definition:
class myobject { public guid uid { get; set; } // other properties }
start with:
ienumerable<myobject> listofobj;
end with:
idictionary<guid, ienumerable<myobject>> dictoflists;
whereby listofobj
contains objects have many different, overlapping values uid property.
using linq:
var dict = input.groupby(elem => elem.identifier) .todictionary(grouping => grouping.key, grouping => grouping.select(x => x));
Comments
Post a Comment