Exforsys
+ Reply to Thread
Results 1 to 4 of 4

What is a delegate method?

This is a discussion on What is a delegate method? within the Microsoft .NET forums, part of the Programming Talk category; see this code: Code: delegate decimal CalculateBonus(decimal sales); Anyone can tell me what does it mean? Thank in advance...

  1. #1
    Yukata is offline Junior Member Array
    Join Date
    Apr 2007
    Answers
    3

    Question What is a delegate method?

    see this code:
    Code:
    delegate decimal CalculateBonus(decimal sales);
    Anyone can tell me what does it mean?
    Thank in advance


  2. #2
    pegas is offline Junior Member Array
    Join Date
    Apr 2007
    Answers
    8
    Tells you that you can create your own function to calculate some bonus that takes and returns decimal. Then you provide the address of that function to the class that exposes the delegate declaration. When you use that class and the class needs to calculate bonuses it will call your function.


  3. #3
    Yukata is offline Junior Member Array
    Join Date
    Apr 2007
    Answers
    3
    Thank you very much. After some lessons, i've known about delegate right now. But i still dont know clearly how and when we use delegate, and advantages and disadvantages in using this method?


  4. #4
    pegas is offline Junior Member Array
    Join Date
    Apr 2007
    Answers
    8
    let's say you are creating a general component that would track sales and salesman. You want to give your client - a programmer who bought your component - some freedom about how the bonus for a salesman is calculated.

    so, you expose the delegate CalculateBonus. Your client writes his own (c#)

    procedure decimal YukataBonus( decimal sales )
    {
    if( sales < 50000.0 )
    {
    return 0.0;
    }
    else if( sales < 550000.0 )
    {
    return (sales - 50000.0)*0.1;
    }
    return 100000.0;
    }

    now your component will get the address of YukataBonus function and it will call it every time it needs to calculate bonus. This way your code cooperates with the code from your user without you giving him any source code.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...