I wrote the following inside my asp.net mvc application:
double d = visits.Average(d=> d.amount);
But the above code ingores any object that is Null, returning an unrealistic result in my case. How can I force the Average function to calculate the average as :
double d = visits.Sum(d=> d.amount)/visit.Count();
So you want null values to be interpreted as 0?
double d = visits.Average(d => d.amount ?? 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With