Created
March 14, 2017 17:21
-
-
Save binki/9a93f8205bdafa803a18ff11e1ed9339 to your computer and use it in GitHub Desktop.
capture still works
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
3 | |
4 | |
5 | |
6 | |
3 | |
4 | |
5 | |
6 |
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 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