Back to course

Delegates: Pointers to Methods

C# Zero to Hero: Comprehensive Programming Masterclass

What is a Delegate?

A delegate is a type that represents references to methods with a particular parameter list and return type.

Usage

csharp public delegate void MyDelegate(string msg);

void ShowMessage(string message) { Console.WriteLine(message); }

MyDelegate del = ShowMessage; del("Hello via Delegate!");

Delegates are the foundation for Events in C#.