What is an example of a delegate?



What is an example of a delegate?..

Answer / Krishna Kant Sharma

A simple example of a delegate in C# is:
```
public delegate int MathOperation(int a, int b);
class Operations
{
public static int Add(int x, int y) { return x + y; }
public static int Subtract(int x, int y) { return x - y; }
}
class Program
{
static void Main()
{
MathOperation op = new MathOperation(Operations.Add);
Console.WriteLine(op(2, 3)); // Output: 5
}
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

When a new instance of a type is created, what is the type of method implicitly called?

2 Answers  


What is the purpose of a console table?

1 Answers  


What is Wrapper class in dot net?

1 Answers   HCL,


List down the differences between “dispose” and “finalize” methods in c#.

1 Answers  


What is tuple in c#?

1 Answers  


This is Kishore i am MCA graduate i have percentage less(52%) in my 10th still i completed .NET course any body tell me how to put fake experience with my BSC degree if you do not mind tell me some fake certificates giving consultencies names in Chennai,Bangalore

5 Answers  


Does c# support properties of array types?

1 Answers  


What are static and dynamic variables?

1 Answers   CGI,


Why do we parse in c#?

1 Answers  


An abstract class is inherited, an Interface also inherited(multiple inheritance), How it differences.

6 Answers   Synechron,


Will finally block get executed if the exception had not occurred?

2 Answers  


how to store the value in textbox using delegates if we have two user control. the value will be called from one user control to another user control. Loading and unloading will be done through delegates.

1 Answers  


Categories