I am trying to get the maximum added value at a given index.
To get the maximum value in each index, try the following:
Dictionary<string, List<double>> dictionary = ...
This will create a new dictionary that preserves the maximum for each value in each index in the original dictionary.
Update
So you have this structure
"Meter1", [ 15, 5, 10 ] "Meter2", [ 10, 50, 20 ]
And you want to calculate the maximum value of the total meter reading at any index. Suppose each List<double> is the same length, then, if I understand correctly, this will be:
Dictionary<string, List<double>> dictionary = ... var length = dictionary.First().Value.Length; var maximum = Enumerable.Range(0, length) .Select(i => dictionary.Values.Select(d => d[i]).Sum()) .Max();
If you also want to get an index where this is the maximum, you can use this:
var result = (from i in Enumerable.Range(0, length) let s = dictionary.Values.Select(d => d[i]).Sum() orderby s descending select new { Index = i, Sum = s }) .First();
source share