Beware - Average Computation Gotcha With LINQ in C# & .NET
[C#, .NET, LINQ]
If you’ve used .NET in any incarnation, you have doubtlessly used LINQ in some way, shape or form.
Recently, I was reviewing some code that reminded me again of the importance of definitions.
Quick, what does this code return?
var numbers = new List<decimal>();
Console.WriteLine(numbers.Average());
This is simply an attempt to compute the average of a list of decimal that does not actually contain any numbers. Average, in some contexts, is also known as the arithmetic mean.
Many would expect this to return a 0.
It does not.
It, in fact, returns an exception, and in particular, an InvalidOperationException.

This is because the average of a set without any elements is undefined. There is a robust discussion of this topic here in MathExchange.
You therefore need to code defensively to avoid this problem.
var average = 0M;
if (numbers.Any())
average = numbers.Average();
Console.WriteLine(average);
Alternatively, depending on your domain logic, you can throw an Exception if you detect an empty set.
TLDR
The average of an empty set is undefined, so you need to check for this in your code.
Happy hacking!