What is callback function explain with an example.

Posted by Kumar_jay99 under C# on 12/12/2012 | Points: 10 | Views : 21985 | Status : [Member] | Replies : 3
What is callback function
explain with an example.




Responses

Posted by: Saratvaddilli on: 12/12/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
simply a callback function means a function which refers to an another function

i.e
1) pointers : which refers to some other variables
2)Virtual functions which refers to other functions
3)delegates in C# which refers to another function
protected void Page_Load(object sender, EventArgs e)

{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}


void Page_LoadComplete(object sender, EventArgs e)
{
throw new NotImplementedException();
}


Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Delegate is used to refer to a function/method. When a function/method is passed to a delegate, more or less we can call the function/method as Call Back Function, because we can call the function/method by using that delegate. Delegate is most used in Events (we can see events everywhere), so why delegate is very important.

If we have this code:

protected void Page_Load(object sender, EventArgs e)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
void Page_LoadComplete(object sender, EventArgs e)
{
throw new NotImplementedException();
}

We can say the method Page_LoadComplete() as Call Back Function. And inner the LoadComplete event, it uses delegate to achieve this feature.
Refer this url
http://msdn.microsoft.com/en-us/library/843s5s5x.aspx


Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Kumar_jay99
plz Mark as Answer if post helps you.

Kumar_jay99, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response