Click here to Skip to main content
16,014,752 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one explain this in brief with sharp example
what is anonymous methods in .net and why used anonymous method
Posted
Comments
raju melveetilpurayil 29-Jul-10 3:44am    
try with google.
Sandeep Mewara 29-Jul-10 4:03am    
Google can give you number of samples to explain you... try it!

1 solution

Creating anonymous methods is essentially a way to pass a code block as a delegate parameter. For example:

Copy// Create a handler for a click event

button1.Click += delegate(System.Object o, System.EventArgs e)
{ System.Windows.Forms.MessageBox.Show("Click!"); };
or


Copy// Create a delegate instance
delegate void Del(int x);
// Instantiate the delegate using an anonymous method
Del d = delegate(int k) { /* ... */ };

By using anonymous methods, you reduce the coding overhead in instantiating delegates by eliminating the need to create a separate method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900