
- Forum
- Programming Talk
- Microsoft .NET
- What is a delegate method?
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...
-
What is a delegate method?
see this code:
Anyone can tell me what does it mean?Code:delegate decimal CalculateBonus(decimal sales);
Thank in advance
-
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.
-
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?
-
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

Reply With Quote





