c# - Sum of Values in SortedList and Condition on Keys -


i want sum values (time range start till end) of sortedlist<datetime, double> linq. keys contain dates of workingdays , values contain number of possible workhours given day. question want answer is, how many hours possible in given timeframe.

i managed count of keys, i'm stuck @ sum.

the code count keys (thanks stackoverflow) looks this:

        double ats = (from n in daysandhours.keys                    n >= start                    n <= end                    select n).count(); 

how have change it, fill ats values in date range?

thanks!

assuming post applying condition want add values, use following code , modify required

double result = daysandhours.where(n => n.key >= start)                             .where(n => n.key <= end)                             .sum(n => n.value) 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -