Reputation: 15
This is what i have and works.
foreach (var group in groupCollection)
{
int maxValue = group.Max(x => {
int value = 0;
if (Int32.TryParse(x[index1].ToString(), out value))
return value;
return value;
}) ;
foreach (var row in group)
{
row[index2] = maxValue;
}
}
But i was wondering if theres a way to simplify this: The following code just assigns what each list already has not the Max value.
groupCollection.ForEach(x => x.Max(y=> {
int value = 0;
if(Int32.TryParse(y[index1].ToString(), out value))
y[index2] = value;
return value;
}));
Keep in mind that groupCollection is a List<List<List<object>>>
Upvotes: 1
Views: 77
Reputation: 26
Try this:
groupCollection.ForEach(x => {
int maxValue = x.Max(y =>
Int32.TryParse(y[index1].ToString(), out var value) ? value : 0);
x.ForEach(y => y[index2] = maxValue);
});
Upvotes: 1