Created
November 29, 2010 06:52
-
-
Save tarnacious/719670 to your computer and use it in GitHub Desktop.
This file contains 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
// That's more exploiting JavaScript closures and global scope than re-writing functions. Can't you do the same in C#? | |
[Test] | |
public void test_we_can_rewrite_variable_in_closure() | |
{ | |
System.Func<string, string> fn = (a) => | |
{ | |
fn = (b) => "Goodbye " + b; | |
return "Hello " + a; | |
}; | |
Assert.AreEqual("Hello slace", fn("slace")); | |
Assert.AreEqual("Goodbye slace", fn("slace")); | |
Assert.AreEqual("Goodbye slace", fn("slace")); | |
} | |
// That worked but I did get into some trouble when I tried to use fn inside fn. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment