Skip to content

Instantly share code, notes, and snippets.

@tarnacious
Created November 29, 2010 06:52
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 tarnacious/719670 to your computer and use it in GitHub Desktop.
Save tarnacious/719670 to your computer and use it in GitHub Desktop.
// 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