A local variable instantiated within a lambda expression is unique per invocation of the delegate instance. : Lambda : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Lambda »

 

A local variable instantiated within a lambda expression is unique per invocation of the delegate instance.








    
 

using System;
delegate int NumericSequence();

class Test {
    static NumericSequence Natural() {
        return () => { int seed = 0; return seed++; };
    }

    static void Main() {
        NumericSequence natural = Natural();
        Console.WriteLine(natural());
        Console.WriteLine(natural());
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Lambda