Skip to content

Instantly share code, notes, and snippets.

@binki
Created March 14, 2017 17:21
Show Gist options
  • Save binki/9a93f8205bdafa803a18ff11e1ed9339 to your computer and use it in GitHub Desktop.
Save binki/9a93f8205bdafa803a18ff11e1ed9339 to your computer and use it in GitHub Desktop.
capture still works
3
4
5
6
3
4
5
6
using System;
namespace LocalFuncCreatesClass
{
class Program
{
static Func<int> GetNextThing { get; set; }
static void Main(string[] args)
{
SeparateFunction();
Console.WriteLine(GetNextThing());
Console.WriteLine(GetNextThing());
Console.WriteLine(GetNextThing());
SeparateFunction();
Console.WriteLine(GetNextThing());
Console.WriteLine(GetNextThing());
Console.WriteLine(GetNextThing());
}
static void SeparateFunction()
{
var current = 2;
int next() { return ++current; };
GetNextThing = next;
Console.WriteLine(next());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment