首页  编辑  

递归调用匿名方法

Tags: /C#/RTTI/   Date Created:

public delegate int Factorial ( int ANumber);

public Factorial vFactorial;

private void button1_Click( object sender , EventArgs e)

{

    int i = 0 ;

   vFactorial = delegate ( int ANumber)

   {

       i ++ ;

        if (ANumber <= 1 ) return 1 ;

        return ANumber * ( int )Invoke(vFactorial, ANumber - 1 );

   };

   Text = Invoke(vFactorial, 10 ) . ToString() + " " + i . ToString();

}