我是新手,帮我看看这个程序错在哪?
用!操作符重载,求一个书的阶乘,阶乘的写法数学上应该是这样的,例子4!,但是好象!重载后,应该是!4;下面这个程序有错误,帮我看看!
static void Main(string[] args)
{ chong l = new chong(3);
Console.WriteLine("goooooooooood");
Console.WriteLine(!l);
Console.WriteLine("gggggggggg");
}
public class chong
{
public int c;
public chong(int n)
{
c = n;
}
public static int operator !(chong a)
{
int gg=nn(a);
//;
return gg;
}
public static int nn(chong g)
{
int d;
if (g.c == 0)
{ return 1; }
chong n = new chong(g.c--);
Console.Write(n.c);????????(这里打印出来一直是3,所以程序运行的时候,会益处!)
d = (g.c+1) * nn(n);
return d;
}
程序的目的是求3的阶乘!请高手指教