Corin - it's not an unsuitable use for generics, what you want to do is something that it should support, but doesn't yet.
kronoz - that would work, but it would be relatively slow and you wouldn't really get the advantage.
What we need is something like:
static bool GenericMathFunction<T>(T value, T otherValue)
where T : operators( +, -, /, *, >, < )
{
//this is just a dumb example to give the idea
//a real equation could be much more complex
return (value * (otherValue - value )) > (otherValue + value * value);
}
//another example, an extension to collections
static T Sum<T>( this IEnumerable<T> collection, T startingValue )
where T : operators( + )
{
T result = startingValue ;
foreach( T item in collection );
result += item;
return result;
}
//this would then allow:
List<long> listOfLongs = new List<long> { 2, 3, 5, 7, 11, 13 .... }
long total = listOfLongs.Sum( 0 );
You just can't do this at the moment, even using kronoz's idea you wouldn't then have access to the Add/Multiply etc methods that you need on the numeric value types.