I have a custom data type that contains a List<string>.
I wish to group a List of CustomDataType by that nested List<string>.
I have tried the following
compoundSchedules.GroupBy(a => a.Timepoints);
Where Timepoints is a list of dates represented as strings. Where any CustomDataTypes have identical timepoints, I wish them to be grouped together.
Using the code above, it does not group them and instead just repeats the List of CustomDataType with its timepoint list as the IGrouping Key.
Thanks.
You should create an
IEqualityComparer<List<string>>that checks that the lists have the same length and contents, and use this overload ofEnumerable.GroupBy:Either that, or create your own class to be a list of Timepoints, and have it implement
GetHashCodeandEquals(and/or implementIEquatable<T>), which are used by the default comparer.