Closure inside a delegate

suggest change

Closures are inline anonymous methods that have the ability to use Parent method variables and other anonymous methods which are defined in the parent’s scope.

In essence, a closure is a block of code which can be executed at a later time, but which maintains the environment in which it was first created - i.e. it can still use the local variables etc of the method which created it, even after that method has finished executing. – Jon Skeet
delegate int testDel();
static void Main(string[] args)
{
    int foo = 4;
    testDel myClosure = delegate()
    {
        return foo;
    };
    int bar = myClosure();

}

Example taken from Closures in .NET.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Delegates:
* Closure inside a delegate

Table Of Contents
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
94 Delegates
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script