Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all, Could you explain to me, how anonymous method and delegate relate together in Linq. Thank you.
Posted

You can look this up, and that is probably best since those are authorities that are telling you the answer.

A delegate defines a signature that is assigned to name so that it can be referenced. Sort of like "int". That way a method can be referenced and passed as an argument or saved in a variable. It is also used with events. Delegates have been in C# since the first release. There are a number of delegates that are defined as part of the language in the later releases that take advanatage of generics, including Action and Func. This means that do not have to define a delegate.

An anonymous method is actually very different. It is basically a method without a name, thus the term anonymous. Also an anonymous method may not have the return type and arguments typed (you can still type them, but most people do not), which is required for normal methods, and an anonymous method can use variable within the method that defines it (and it has to be defined in a method). The problem with anonymous methods is that they are hard to reuse (could possibly assign an anonymous method to a variable defined by a delegate, but not sure).
 
Share this answer
 
 
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