The list of doubles SC
is of same size for all of CTable
.
I would like add SC grouped by CTable.Ch
. The result should be a List of sums. Is there an operator/customization for that?
Public Class SCRow
Public L As String
Public Ch As String
Public SC As List(Of Double)
End Class
Dim CTable AS New List(Of SCRow)
Dim AggrC =
From C In CTable
Group C By Key = C.Ch
Into Group
Select New With
{
.Ch= Key,
.SumSC = Group.Sum(Function(x) ???)
}
Example:
CTable.Add(New SCRow With {.L = "L1", .Ch = "Ch1", .SC = New List(Of Double)(New Double() {1.0, 2.0})})
CTable.Add(New SCRow With {.L = "L1", .Ch = "Ch2", .SC = New List(Of Double)(New Double() {3.0, 4.0})})
CTable.Add(New SCRow With {.L = "L2", .Ch = "Ch1", .SC = New List(Of Double)(New Double() {5.0, 6.0})})
Output:
Ch1 {6=1+5, 8=2+6}
Ch2 {3, 4}
It can be done using Aggregate extension method along with Zip method. I have written the code in C#. Please translate it to VB.Net. Hope it will help.
Aggregate: Performs a specified operation to each element in a collection, while carrying the result forward.
Zip: The Zip extension method acts upon two collections. It processes each element in two series together.