Hacker News new | past | comments | ask | show | jobs | submit login

The problem is the types. Those methods do know how to handle 0-sized collections, but they must be operating on nullable types.

Enumerable.Empty<int?>().Average() returns null.

If you have a sequence of integers, you can get the behavior you want by converting the elements to nullable types like this. seq.Average(x => (int?)(x))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: