Reference the local variables from lambda in CSharp
Description
The following code shows how to reference the local variables from lambda.
Example
/*from www. jav a2s . com*/
using System;
delegate int NumericSequence();
class Test {
static void Main() {
int seed = 0;
NumericSequence natural = () => seed++;
Console.WriteLine(natural());
Console.WriteLine(natural());
}
}
The code above generates the following result.