A Step Too Far

Occasionally, I have a bit of a compulsive behavior. When presented with a challenge, I usually won’t give up until I have a working answer… and sometimes that answer get’s a little crazy. Here’s one of my more recent journeys down that path. I was asked, “Hey Kevin. I am a method that accepts a type parameter, ‘T’. Is there a type constraint I can add to T so that I may sum them?” As an example, consider this code:  public string FormatNumber<T>(T t1, T t2) where T:IFormattable { T sum = t1 + t2; return String.Format(“{0:N2}”, sum); } This … Continue reading A Step Too Far