A Confused Programmer's Blog

This blog is dedicated to C# and Java programming that I happen to do for living – with accent on curious cases and with sincere intent to make the world of coding a slightly better place as a result

No super class for numeric values in C#? Not cool, dudes

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)
  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.

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

REST Assured and une

If you stumbled onto this article, it is safe to ...

Getting rid of Error

Since I upgraded my Windows 8 to Windows 10, I ...

Bypassing EULA step

We are working on automated testing of virtual appliance. This appliance ...

How I got rid of "Ac

OVF is a VMware virtual appliance format which allows you ...

My use-case of Perfo

In my blog I am set on a mission to ...

Twitter updates

RSS not configured