I want to write a generic function to calculate factorial in C# … like:
static T Factorial<T>(T n)
{
if (n <= 1)
return 1;
return Factorial<T>(n - 1);
}
but obviously having restriction that we can’t perform operations on type ‘T‘. any alternative?
int y = p.Factorial(3, 1, (a, b) => a * b, (a) => –a, (a, b) => (a <= b) ? false : true);