Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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