Created
September 28, 2017 11:11
-
-
Save NMZivkovic/05e3c893bca631a93d5bc814f7dbd06e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ClosureExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Action counterIncrementAction = CounterIncrementAction(); | |
counterIncrementAction(); | |
counterIncrementAction(); | |
Console.ReadLine(); | |
} | |
static Action CounterIncrementAction() | |
{ | |
int counter = 0; | |
return delegate | |
{ | |
counter++; | |
Console.WriteLine("Counter value is {0}", counter); | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment