Understanding Delegate in C#

Few days before I thought of writing about lambda expression, but while I read about lambda expression, I realized, it is essential to write about delegates. so here is an article about delegate, once after this, I will write about lambda expression, an anonymous method.

Delegate

  • Delegate itself a type and it is of type reference.
  • Delegate can have a return type and any number of arguments of any types.
  • Delegate can be used to encapsulated with named methods or anonymous method.
  • Delegate are similar to function pointers in c++
  • Delegates are type-safe and secure
  • Delegates are basis for Events in C#.
  • Delegates must be instantiated with method or lambda expression.

Steps to create and use delegate in your programs.

  • Declare a delegate type.
  • Use the delegate your type in your program.

Delegate declaration in C#

Using Delegate in C#

Output

Delegate output

Delegate output

0 comments… add one

Leave a Comment