Return a lambda function in CSharp
Description
The following code shows how to return a lambda function.
Example
/*www . j a va 2 s . c o m*/
using System;
delegate int NumericSequence();
class Test {
static NumericSequence Natural() {
int seed = 0;
return () => seed++;
}
static void Main() {
NumericSequence natural = Natural();
Console.WriteLine(natural());
Console.WriteLine(natural());
}
}
The code above generates the following result.