Suppose I have a list with a Tuple.First as a string[] (i.e. my key):
var lst = new List<Tuple<string[], int>> {
new Tuple<string[], int>(new string[] { "A", "B" }, 5),
new Tuple<string[], int>(new string[] { "A", "B" }, 10),
new Tuple<string[], int>(new string[] { "C", "B" }, 10),
}
I would like to aggregate (e.g. Sum) by Tuple.First (i.e. string[]) so expecting an output as follows:
var output = new List<Tuple<string[], int>> {
new Tuple<string[], int>(new string[] { "A", "B" }, 15),
new Tuple<string[], int>(new string[] { "C", "B" }, 10),
}
I did it this way but there must be a cleaner way to do it instead of forcing a pipe concatenation:
var output = lst
.GroupBy(x => string.Join("|", x.First))
.Select(x => new Tuple<string[], int>(
x.Key.Split('|'),
Sum(x => x.Second)));
Pairclass come from? How do you access the values that you pass to its constructor?