Delegates and events in c
- use of delegates in c
- example of delegates in c
Generic delegates in c!
Types of delegates in c# with example
C# Delegates
A delegate is an object which refers to a method or you can say it is a reference type variable that can hold a reference to the methods. It provides a way which tells which method is to be called when an event is triggered.
For example, if you click on a Button on a form (Windows Form application), the program would call a specific method.
In simple words, it is a type that represents references to methods with a particular parameter list and return type and then calls the method in a program for execution when it is needed.
Declaration of Delegates
Delegate type can be declared using the delegate keyword.
Once a delegate is declared, delegate instance will refer and call those methods whose return type and parameter-list matches with the delegate declaration.
Syntax:
[modifier] delegate [return_type] [delegate_name] ([parameter_list]);- modifier: It is the required modifier which defines the access of delegate and it is optional to use.
- delegate:It is the keyword which is used to define the delegate.
- return_t
- application of delegates in c