Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 3:58
ashish712-Jul-12 3:58 
GeneralRe: Query on Delegate Pin
OriginalGriff12-Jul-12 4:11
mveOriginalGriff12-Jul-12 4:11 
GeneralRe: Query on Delegate Pin
DaveyM6912-Jul-12 4:32
professionalDaveyM6912-Jul-12 4:32 
AnswerRe: Query on Delegate Pin
Abhinav S11-Jul-12 21:53
Abhinav S11-Jul-12 21:53 
QuestionConfusion Pin
nitish_0711-Jul-12 21:02
nitish_0711-Jul-12 21:02 
AnswerRe: Confusion Pin
Abhinav S11-Jul-12 21:41
Abhinav S11-Jul-12 21:41 
AnswerRe: Confusion Pin
OriginalGriff11-Jul-12 21:41
mveOriginalGriff11-Jul-12 21:41 
AnswerRe: Confusion Pin
BillWoodruff14-Jul-12 15:17
professionalBillWoodruff14-Jul-12 15:17 
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:
C#
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:
C#
// 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.

General[SOLVED] Adding Forms to TabControl Pin
AmbiguousName11-Jul-12 18:27
AmbiguousName11-Jul-12 18:27 
AnswerRe: Adding Forms to TabControl Pin
BobJanova11-Jul-12 23:29
BobJanova11-Jul-12 23:29 
GeneralRe: Adding Forms to TabControl Pin
AmbiguousName12-Jul-12 0:13
AmbiguousName12-Jul-12 0:13 
GeneralRe: Adding Forms to TabControl Pin
BobJanova12-Jul-12 4:05
BobJanova12-Jul-12 4:05 
GeneralRe: Adding Forms to TabControl Pin
AmbiguousName12-Jul-12 20:11
AmbiguousName12-Jul-12 20:11 
GeneralExposing a queue as a public property Pin
JoeRip11-Jul-12 17:44
JoeRip11-Jul-12 17:44 
GeneralRe: Exposing a queue as a public property Pin
PIEBALDconsult11-Jul-12 19:50
mvePIEBALDconsult11-Jul-12 19:50 
GeneralRe: Exposing a queue as a public property Pin
Abhinav S11-Jul-12 19:59
Abhinav S11-Jul-12 19:59 
GeneralRe: Exposing a queue as a public property Pin
BobJanova11-Jul-12 23:27
BobJanova11-Jul-12 23:27 
GeneralRe: Exposing a queue as a public property Pin
JoeRip12-Jul-12 6:58
JoeRip12-Jul-12 6:58 
GeneralRe: Exposing a queue as a public property Pin
BobJanova12-Jul-12 23:41
BobJanova12-Jul-12 23:41 
GeneralRe: Exposing a queue as a public property Pin
PIEBALDconsult13-Jul-12 3:44
mvePIEBALDconsult13-Jul-12 3:44 
GeneralRe: Exposing a queue as a public property Pin
JoeRip13-Jul-12 8:35
JoeRip13-Jul-12 8:35 
GeneralRe: Exposing a queue as a public property Pin
PIEBALDconsult14-Jul-12 4:13
mvePIEBALDconsult14-Jul-12 4:13 
QuestionPost build event using XML Pin
manishsaiin11-Jul-12 5:58
manishsaiin11-Jul-12 5:58 
AnswerRe: Post build event using XML Pin
Dave Kreskowiak11-Jul-12 7:03
mveDave Kreskowiak11-Jul-12 7:03 
AnswerRe: Post build event using XML Pin
eupendra15-Jul-12 18:58
eupendra15-Jul-12 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.