Today I discovered a surprising C# limitation: apparently (as of .Net 3.5) numeric types in C# do not share common super class. I believe that this feature would come quite handy in cases like mine. My goal was to write a function that calculates average value of some numeric collection without taking into account top 10% and bottom 10%. So the code I came up with was:
public static double AverageWithoutExtremeValues(List<double> values)
{
values.Sort();
return values.Skip((int)Math.Round(values.Count * 0.1))
.Take((int)Math.Round(values.Count * 0.8)).Average();
}
Unfortunately, I was unable to extend this code to be more generic, something like:
public static T AverageWithoutExtremeValues<T>(List<double> latencies) where T : decimal
{
...
}
After a brief investigation, I discovered that many good folks had the same complaints (for example, c-sharp-numeric-base-class). My colleagues told me that in Java such base class exists. Perhaps it is time to add this feature to the wishlist for the next .Net release.