我有一个包含4个大小的数组的列表:

这些数组有4个元素.我想使用包含这些数组的第一个元素计数的另一个列表.另外,如果它们的第一个元素相同,则它们应该是求和的.例如:
list[0] = {1,2,3,4}
list[1] = {1,1,5,3}
list[2] = {1,2,5,8}
list[3] = {2,2,3,3}
list[4] = {3,5,5,6}
list[5] = {4,4,4,4}
list[6] = {4,5,5,6}
Run Code Online (Sandbox Code Playgroud)
所以,anotherList应该是:
anotherList = {3, 1, 1, 2}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
编辑:预期结果是:

anotherList = list.Select(a => a[0]) // project each array to its first item
.GroupBy(x => x) // group first items by their value
.Select(g => g.Count()) // select count of same items
.ToList();
Run Code Online (Sandbox Code Playgroud)
输出:
[ 3, 1, 1, 2 ]
Run Code Online (Sandbox Code Playgroud)
注意:GroupBy在内部使用Lookup,它以与添加的顺序相同的顺序返回组,因此它似乎就是您想要的.
更新:不依赖于GroupBy内部实现的方法
anotherList = list.Select((a,i) => new { Item = a[0], Index = i })
.GroupBy(x => x.Item)
.OrderBy(g => g.Min(x => x.Index))
.Select(g => g.Count())
.ToList();
Run Code Online (Sandbox Code Playgroud)