I am learning C #. I mean closing as a construct that can adopt the changes in the environment in which it is defined.
Example:
List<Person> gurus = new List<Person>() { new Person{id=1,Name="Jon Skeet"}, new Person{id=2,Name="Marc Gravell"}, new Person{id=3,Name="Lasse"} }; void FindPersonByID(int id) { gurus.FindAll(delegate(Person x) { return x.id == id; }); }
The id variable is declared in the scope of FindPersonByID (), but we can still access the local id variable inside the anonymous function (ie) delegate(Person x) { return x.id == id; } delegate(Person x) { return x.id == id; }
(1) Is my understanding of closure correct?
(2) What are the benefits we can get from closing?
closures c # linq anonymous-methods
user274364
source share