Generic Factorial function in C#
Posted
by mqpasta
on Stack Overflow
See other posts from Stack Overflow
or by mqpasta
Published on 2010-03-09T15:51:09Z
Indexed on
2010/03/13
12:55 UTC
Read the original article
Hit count: 344
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?
© Stack Overflow or respective owner