Closure inside a delegate C# with Example



Closure inside a delegate C# with Example

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. 
 

Parameter Details 
path The location of the file. 
append If the file exist, true will add data to the end of the file (append), false will overwrite the file. 
text Text to be written or stored. 
contents A collection of strings to be written. 
source The location of the file you want to use. 
dest The location you want a file to go to. 
Manages files. 

0 Comment's

Comment Form

Submit Comment