I am going to dare to respond with an emphasis that is a bit at variance with the two other commentators' remarks here (both of whom I regard, personally, as "CodeProject Bacon, prime cut, extra-lean," and respected mentors). I must, however, on one point, dare to question OG's description of a delegate as a "variable." I don't think that's a helpful way to describe what they are, particularly to those just getting into the concept, even though it's "technically true," on a certain level. I would describe a delegate as a Type which is a declaration of a signature of an encapsulated Method. Where "signature" means a specification of the types of expected output Type and inputs (usual list of parameters) that instances of the delegate will, later, "contain." Numerous instances of the delegate can be created: as long as each new instance of the delegate has assigned to it a method (or an in-line anonymous method is provided, and assigned) whose parameters match the signature of the delegate: you have a "legal" instance of the delegate. Let's look at a trivial example of using the same delegate more than once:
public delegate int trivialDelegate(int int1, int int2);
public static int AddEm(int int1,int int2)
{
return int1 + int2;
}
public static int DivEm(int int1,int int2)
{
return int1 / int2;
}
public static trivialDelegate lateBoundAdd = AddEm;
public static trivialDelegate lateBoundDiv = DivEm;
// example of in-line anonymous method expressed in lambda form
public static trivialDelegate lateBoundSub = (int1, int2) => int1 - int2;
So, now, somewhere in your code at run-time, you can invoke these late-bound methods:
// somewhere in your code ... later
int addResult = lateBoundAdd(100, 200);
int divResult = lateBoundDiv(1000, 333);
int subResult = lateBoundSub(999, 666);
So, what's the big deal about "late-binding:" it means you could change the code in the method that is assigned to delegate, at any time, and add other calls to it, do other things with it, at run-time, as long as your new method assigned to the instance name "obeys" the signature of the delegate's required syntax.
The glyphs you are reading now: are place-holders signifying the total absence of a signature.