Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created September 28, 2017 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/05e3c893bca631a93d5bc814f7dbd06e to your computer and use it in GitHub Desktop.
Save NMZivkovic/05e3c893bca631a93d5bc814f7dbd06e to your computer and use it in GitHub Desktop.
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