O'Reilly logo

C# Quick Syntax Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 26

image

Delegates

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 s);

A method that matches the delegate’s signature can be assigned to a delegate object of this type.

class MyClass{   static void Print(string t)  {     System.Console.Write(t);  }     static void Main()  {     MyDelegate d = Print;  } } 

This delegate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required