© Mikael Olsson 2020
M. OlssonC# 8 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-5577-3_26

26. Delegates

Mikael Olsson1 
(1)
HAMMARLAND, Finland
 
A delegate is a type used to reference a method. This allows methods to be assigned to variables and passed as arguments. The delegate’s declaration specifies the method signature to which objects of the delegate type can refer. Delegates are by convention named with each word initially capitalized, followed by Delegate at the end of the name.
delegate void MyDelegate(string str);
A method that matches the delegate’s signature can be assigned to a delegate object of this type.
class MyClass
{
  static void Print(string s)
  {
    System.Console.WriteLine(s);
  }
  static void Main()
  {
    MyDelegate d = ...

Get C# 8 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.