Possible Duplicate:
C# generic constraint for only integers
As you can see in the following code, I need to compute the sum of two generic numbers.
public class NumberContainer<T>
{
public T ValueA { get; private set; }
public T ValueB { get; private set; }
public T Total { get { return ValueA + ValueB; } }
}
However, it isn't possible to do a direct addition of the two T values, which results in the compiler error below :
Operator '+' cannot be applied to operands of type 'T' and 'T'
Given that I don't intend to use T for anything else than value-types that represent numbers (short, ushort, int, uint, etc), how could I perform the sum? (efficiency is a factor to be considered)