A lambda expression can reference the local variables and parameters of the method in which it's defined.

image_pdfimage_print
   
 


using System;
delegate int NumericSequence();

class Test {
    static void Main() {
        int seed = 0;
        NumericSequence natural = () => seed++;
        Console.WriteLine(natural());
        Console.WriteLine(natural());
    }
}

    


This entry was posted in LINQ. Bookmark the permalink.