What is Delegate? Explain in brief

Question: What is Delegate? Explain in brief.


What is Delegate? Explain in brief

Definition of Delegate:
   (Entry 1 of 2): a person empowered to act on behalf of another: as. a : a person who is authorized to perform another's duties under a contract. b : a representative to a convention (as of a political party) or conference.

What is the synonym of delegate?
   Delegate(n) Synonyms: deputy, proxy, vicar, commissioner, legate, envoy, appointee, surrogate

What is Delegate? Explain in brief.
  • The Delegate is a function pointer we can say it is like a pointer to a function.
  • It is a reference data type and it holds the reference of a function.
  • All the delegates are implicity derived from System.Delegate namespace.
  • In the .NET environment a delegate is a type that defines a method signature and it can pass a function as a parameter.
  • In simple word we can say delegate is a .NET object which points to a method that matches its specific signature.
In simple word we can say delegate is a .NET object which points to a method that matches its specific signature.

  • A Delegate can be declared using delegate keyword followed by a function signature.

Syntax:

<access_modifier> delegate <return_Type> <delegate_name> (<parameters>)

Example:
Public delegate void delegatemethod(int n1); 

  • The delegatemethod delegate show above, can be used to print to any method that has same return type (void) & parameters declared in delegatemethod with int data type.
Example:
  1. using System;
  2. public delegate void Fprint();
  3. namespace Test
  4. {
  5.           Class program
  6.            {
  7.                      public Static void hello()
  8.                      {
  9.                                Console.WriteLine("hello all");
  10.                                Console.ReadLine();
  11.                      }
  12.                      public Static void main()
  13.                      {
  14.                                 Fprint fp = new Fprint(hello); 
  15.                                 fp();
  16.                      }
  17.             }
  18. }

Download the Android app to get all Government Job Notifications on your Mobile.
Download Now
Important: Please always Check and Confirm the above details with the official Advertisement / Notification.
Previous Post Next Post