Skip to content

Instantly share code, notes, and snippets.

@agocke
Created September 7, 2017 19:28
Show Gist options
  • Save agocke/d9ce886358bdf26b185a81885f9afe25 to your computer and use it in GitHub Desktop.
Save agocke/d9ce886358bdf26b185a81885f9afe25 to your computer and use it in GitHub Desktop.
Interesting output from local functions
public class C {
public void M() {
int x = 0;
{
int y = 0;
// Captures two struct closures
int L() => x + y;
}
}
}
----
public class C {
int x = 0;
public void M() {
int y = 0;
// This + struct closures
int L() => x + y;
L();
}
}
----
public class C {
int x = 0;
public void M() {
// This-only closure
int L() => x;
L();
}
}
----
using System;
public class C {
public void M(int x) {
Func<int> f = () => x;
// Located in same closure environment
int L() => x;
L();
}
}
----
using System;
public class C {
public void M(int x) {
{
int y = 0;
Func<int> f = () => x;
// Same class environment, with struct env
int L() => x + y;
L();
}
}
}
----
using System;
public class C {
public void M(int x) {
{
int y = 0;
Func<int> f = () => x;
{
Func<int> f2 = () => x + y;
int z = 0;
// Capture struct and through class env chain
int L() => x + y + z;
L();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment