One way is to provide the delegate with an argument for himself:
delegate void Foo(Foo self);
...
list.Add(delegate (Foo self) { list.Remove(self);});
...
foreach (Foo f in list) f(f);
Another way would be to close the variable, referring to itself:
Foo foo;
foo = delegate() { list.Remove(foo);}
list.Add(foo);
source
share