Delegate,` a keyword, is used to create method objects. With the Invoke method we can call a delegate as a method. And we can pass the delegate as an argument to another method. A delegate is a higher-order procedure.`Example.` This program declares a delegate type D that receives a string, and returns no value. In Main, we create an instance of type D. We specify the method body with a lambda expression. `Then: `We call the delegate D method implementation with the argument "cat" using the Invoke method. This is appropriate for the Internet.`This program uses the "delegate" keyword. But many programs use higher-order procedures with just lambda expressions.`Lambda.` The syntax for delegate functions can be complex. Lambda expressions provide a simple and terse way of specifying functions. They use the => syntax to separate formal parameters and the method body. `Lambda: Syntax `lambda`Lambda expressions are used throughout C# programs. Common methods receive them as arguments.`Tip 2: `Whenever you see a method that receives a Predicate, Action, Func or Comparison, a lambda can be passed.`Example 2.` Next, we build upon the delegate concept. We declare a delegate type UppercaseDelegate. It receives a string, and returns a string. We create instances of this delegate Type in the Main method. `We need a delegate declaration to create instances of the delegate type using the new-operator.`Important: `When you construct instances of the delegate type, the target method must have the same return value and arguments.`In this example,` WriteOutput is called three times—it receives two arguments each time. The second argument is of type UppercaseDelegate. In Main, the UppercaseDelegate instances are constructed with the delegate constructor. `The target method is specified as the sole argument. It is a method name, not a variable.`Finally: `In WriteOutput, the UppercaseDelegate argument is invoked. We use two parentheses after the parameter name.`Anonymous function.` Anonymous functions include lambda expressions. You can pass a lambda expression as the implementation of the delegate. You can construct the UppercaseDelegate by specifying a lambda expression inside the constructor itself. `This is functionally equivalent to using a static method with the same return value and argument.`Anonymous Functions `anonymous-function`Action.` In the .NET Framework, Action instances represent a method that returns void. You can call Invoke on the Action instance and then the method will execute. These are useful in a variety of program contexts. `Action `action`Func.` A Func instance is a delegate to a method that receives arguments and returns a value. It is used in the same general way as Action, but it has a return value. So you can assign variables to its result. `Func `func`Events.` Events allow you to specify that when external event occurs, such as a mouse click, a delegate method should always be executed. Events are most commonly used in user interfaces such as Windows Forms. `But: `You can define custom events in any program. They are occasionally useful in complex programs.`Event `event`LINQ.` In LINQ extensions, delegate methods are extensively used. Even query expressions (such as select statements) are implemented with methods that receive delegates. Many extension methods require delegate use. `LINQ `linq`Summary.` Delegate syntax is at first confusing. Once you understand the instantiation model and type system, it is useful. With the type system, the language offers the ability to specify actions as data.

NHGBVGGHDHQHbHJHAG{GNVdelegateV HcD(HP Hh)HbNH%N{VGNNH9Specify delegate with lambda expression.GNNVD dHyv => VH'v)V;VGNNH9Invoke delegate.GNNVd.Invoke(BcatB);GN}G}GGVGGcatVHA 2 that uses delegate type: C#VGGHDHQHbHJHAG{GNVdelegateV HP UppercaseDelegate(HP input)HbNH?HP UppercaseFirst(HP input)GN{GNNchar[] bufferHyinput.ToCharHS();GNNbuffer[0]Hychar.ToUpper(buffer[0]);GNNHK HqHP(buffer);GN}GGNH?HP UppercaseLast(HP input)GN{GNNchar[] bufferHyinput.ToCharHS();GNNbuffer[buffer.LH^ - 1]Hychar.ToUpper(buffer[buffer.LH^ - 1]);GNNHK HqHP(buffer);GN}GGNH?HP UppercaseAll(HP input)GN{GNNHK input.ToUpper();GN}GGNH?HcHaOutput(HP input, UppercaseDelegate del)GN{GNNH'BYour HP beH|e: {0}B, input);GNNH'BYour HP after: {0}B, del(input));GN}GGNH%N{VGNNH{Wrap the mHgs inside delegate instancesHVpassHjthe mHg.GNNVHaOutput(BperlsB, HqUppercaseDelegate(UppercaseFirst));GNNHaOutput(BperlsB, HqUppercaseDelegate(UppercaseLast));GNNHaOutput(BperlsB, HqUppercaseDelegate(UppercaseAll));GN}G}GGVGGYour HP beH|e: perlsGYour HP after: PerlsGYour HP beH|e: perlsGYour HP after: perlSGYour HP beH|e: perlsGYour HP after: PERLSVGGHDHQHbHJHAG{VGNH{...GNH9(Paste other mHgs here)GNH{...GGNVH%N{GNNHaOutput(BperlsB, HqUppercaseDelegate(x => x.ToUpper()));GN}G}GGVGGPERLSV

"Xkdelegatelambda expression, delegate