Possible Duplicates:
C# generic constraint for only integers
Generics - where T is a number?
In c#:
Imagine a case that we have a functionality over a generic type in which conceptually our generic type is limited only to numbers.
By saying "number" we aim to be able to use multiply, plus, minus, etc. operators on variables of type T.
Unfortunately something like this is not accepted in c#:
public class Image<T> where T : number
Note that performance is also important so we don't want to go for redefining a struct for numeric types and using them.
What do you think is the best way to do this? Or is there any design patter that allows us to have "high performance" arithmetic functions over variables of a generic type?