Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What are delegates?

delegates
0
Posted

What are delegates?

0

A delegate is a class derived from System.Delegate. However the language has a special syntax for declaring delegates which means that they don’t look like classes. A delegate represents a method with a particular signature. An instance of a delegate represents a method with a particular signature on a particular object (or class in the case of a static method). For example: using System; delegate void Stereotype(); class CAmerican { public void BePatriotic() { Console.WriteLine( “… … God bless America.”); } } class CBrit { public void BeXenophobic() { Console.WriteLine( “Bloody foreigners … ” ); } } class CApplication { public static void RevealYourStereotype( Stereotype[] stereotypes ) { foreach( Stereotype s in stereotypes ) s(); } public static void Main() { CAmerican chuck = new CAmerican(); CBrit edward = new CBrit(); // Create our list of sterotypes. Stereotype[] stereotypes = new Stereotype[2]; stereotypes[0] = new Stereotype( chuck.BePatriotic ); stereotypes[1] = new St

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.