Whenever you have a series of items with a single key referencing multiple items, you can use a Lookup object:
var lookup = list.ToLookup( item => item.Sequence, item => item.Terms);
This code tells c# to create a lookup, which is just like a dictionary where item.Sequence
is the key and item.Terms
is the value. The value itself is a list which can be enumerated:
foreach (var item in lookup)
{
Console.WriteLine("Sequence {0} has these terms: {1}", item.Key, string.Join(",", item));
}
Output:
Sequence 1438690 has these terms: weather,the elements
Sequence 9672410 has these terms: dogs,cats
See my working example on DotNetFiddle