What is Delegates in C#, how to declare and use C# Delegates
What is Delegates in C#, how to declare and use C#
Delegates:
Delegates in C#, how to declare:
In other programming language like C++, Pascal gives the
facility of function pointer. Similar in C#(object-oriented language) use
delegate. C# delegate enable encapsulate both an object and instance and a
method. A delegate declaration defines a class that is derived from the class
System.Delegate. A delegate instance encapsulates an invocations list, which is
a list one or more method, each of which is referred to as callable entity.
A delegate defines a reference type that can be used to
encapsulate a method with a specific signature.
C# delegate Life cycle:
The life cycle of C# delegate is
- Declaration
- Instantiation
- INVACATION
C# delegate Declarations:
Delegate declaration is a type declaration that declare a
new delegate type .
SYNTAX OF DELEGATE DECLARATION :
[modifier] delegate [return type][identifier]( formal
parameters)
EXAMPLE OF DLEGATE:
Public delegate int MYFirstDelegate(int i)
DELEGATE –MODIFIER:
- new
- public
- protected
- internal
- private
The modifiers control accessibility of delegate. Depending
on the delegate context in which the delegate deceleration occurs.
Comments
Post a Comment