C#: Recursive functions with Lambdas

前端 未结 4 690
死守一世寂寞
死守一世寂寞 2020-12-01 04:34

The below does not compile:

Func fac = n => (n <= 1) ? 1 : n * fac(n - 1);

Local variable \'fac\' migh

4条回答
  •  情歌与酒
    2020-12-01 04:59

    Well geez, if you'd just typed "why does a recursive lambda cause a definite assignment error?" into some search engine, you'd have found the answer in my article on the subject.

    :-)

    http://blogs.msdn.com/ericlippert/archive/2006/08/18/why-does-a-recursive-lambda-cause-a-definite-assignment-error.aspx

提交回复
热议问题