Home

Advertisement

C#: recursive call to anonymous method

  • May. 6th, 2008 at 11:58 AM
http://www.flickr.com/photos/20958118@N0
 
Func<>の定義をLambda表現(もしくはdelegate(){} )のステートメントの前にしないとコンパイルエラーになります。 
       private void ButtonAnonyMethodInfo_Click(object sender, EventArgs e)
        {
            Func<int, int,int> f = null;
            f = (i,j ) => { return ( i < 5 ) ? i + j : f(i-1,j ) ; };

            MessageBox.Show(f(20, 3).ToString());
        }
WS000005

Hatena タグ: