Exforsys

Online Training

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...


Go Back   Exforsys > Programming Talk > Microsoft .NET

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-07-2007, 05:47 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Yukata is on a distinguished road
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
__________________
Think about bigger things
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2007, 02:13 PM
Junior Member
 
Join Date: Apr 2007
Posts: 8
pegas is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2007, 03:12 PM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Yukata is on a distinguished road
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?
__________________
Think about bigger things
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2007, 05:57 PM
Junior Member
 
Join Date: Apr 2007
Posts: 8
pegas is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Best Practices for Checking Prerequisites Mario T. Lanza Software Patterns 2 09-01-2004 06:51 PM
Objective-C FAQ stes@pandora.be Tech FAQ 0 06-18-2004 02:58 PM
Objective-C FAQ stes@pandora.be Tech FAQ 0 05-18-2004 02:59 PM
Smalltalk FAQ (v.1.0) Vikas Malik Tech FAQ 0 04-17-2004 08:27 AM
Objective-C FAQ stes@pandora.be Tech FAQ 0 04-16-2004 02:51 PM


All times are GMT -4. The time now is 01:28 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.