Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
QuestionWPF Interoperability problem Pin
newstargate31-Jan-10 12:22
newstargate31-Jan-10 12:22 
AnswerRe: WPF Interoperability problem Pin
Not Active31-Jan-10 13:22
mentorNot Active31-Jan-10 13:22 
AnswerRe: WPF Interoperability problem Pin
Pete O'Hanlon31-Jan-10 23:04
mvePete O'Hanlon31-Jan-10 23:04 
Questionnetwork programming Pin
hotthoughtguy31-Jan-10 9:18
hotthoughtguy31-Jan-10 9:18 
AnswerRe: network programming Pin
Abhinav S31-Jan-10 10:07
Abhinav S31-Jan-10 10:07 
AnswerRe: network programming Pin
mehrdad33331-Jan-10 12:48
mehrdad33331-Jan-10 12:48 
AnswerRe: network programming Pin
Rod Kemp31-Jan-10 19:10
Rod Kemp31-Jan-10 19:10 
QuestionHow do delegates work? Pin
Neo1010131-Jan-10 9:12
Neo1010131-Jan-10 9:12 
How do they work?
I'm having a hard time understanding them.
I've read up on several examples but the code approach just seems strange to me (I'm not a C/C++ programmer so I am not used to function pointers).

Can delegates be compared to Java's addActionListener(new MyHandler());?
If they can, then it would help me understand this far better.
Basically, in Java you add an event handler (java.awt.event.*) to an object (e.g. a button)
and then you tell it that when an action happens on that button (such as being clicked),
said method will be assigned to handle it (MyHandler).

Implemented, it looks like this:

myButton.addActionListener(new MyHandler());

class MyHandler implements ActionListener
{
    public void actionPerformed(ActionEvent e)
    {
        doStuff();
    }
}


To my analogy, this would compare to C# like this:

myButton.Click += new System.EventHandler(MyHandler);

public void MyHandler(Object o, EventArgs e)
{
    doStuff();
}


So as far as I understood, a delegate delegates the task of doing something, to
a method that has the same signature as the delegate.
What about System.EventHandler(MyMethod) then?
Is one passing a method to EventHandler() as an argument
or is MyMethod replacing EventHandler by its signature?
Do I have to take callback functions in account to understand delegates?

I'm still confused, but I will read up on it (even though I've read a lot about delegates).

Thanks for reading.
Treval
AnswerRe: How do delegates work? Pin
Abhishek Sur31-Jan-10 9:55
professionalAbhishek Sur31-Jan-10 9:55 
GeneralRe: How do delegates work? Pin
Neo1010131-Jan-10 10:12
Neo1010131-Jan-10 10:12 
AnswerRe: How do delegates work? Pin
PIEBALDconsult31-Jan-10 15:25
mvePIEBALDconsult31-Jan-10 15:25 
Question"BindingSource.ResetBindings" is not working Pin
Said Ali Jalali31-Jan-10 7:07
Said Ali Jalali31-Jan-10 7:07 
QuestionGet visible part from a Form / Control Pin
shantz31-Jan-10 6:27
shantz31-Jan-10 6:27 
AnswerRe: Get visible part from a Form / Control Pin
OriginalGriff31-Jan-10 10:22
mveOriginalGriff31-Jan-10 10:22 
AnswerRe: Get visible part from a Form / Control Pin
Luc Pattyn31-Jan-10 14:33
sitebuilderLuc Pattyn31-Jan-10 14:33 
QuestionAccessing data without using database (.Net 2005). Pin
priyamtheone31-Jan-10 5:39
priyamtheone31-Jan-10 5:39 
AnswerRe: Accessing data without using database (.Net 2005). Pin
Not Active31-Jan-10 5:43
mentorNot Active31-Jan-10 5:43 
GeneralRe: Accessing data without using database (.Net 2005). Pin
priyamtheone31-Jan-10 6:15
priyamtheone31-Jan-10 6:15 
GeneralRe: Accessing data without using database (.Net 2005). Pin
Not Active31-Jan-10 6:34
mentorNot Active31-Jan-10 6:34 
GeneralRe: Accessing data without using database (.Net 2005). Pin
Saksida Bojan31-Jan-10 7:37
Saksida Bojan31-Jan-10 7:37 
AnswerRe: Accessing data without using database (.Net 2005). Pin
DaveyM6931-Jan-10 7:37
professionalDaveyM6931-Jan-10 7:37 
Questionhow to convert Urdu Language in english language? Pin
roheen31-Jan-10 2:19
roheen31-Jan-10 2:19 
AnswerRe: how to convert Urdu Language in english language? PinPopular
OriginalGriff31-Jan-10 2:35
mveOriginalGriff31-Jan-10 2:35 
GeneralRe: how to convert Urdu Language in english language? Pin
DaveyM6931-Jan-10 4:43
professionalDaveyM6931-Jan-10 4:43 
GeneralRe: how to convert Urdu Language in english language? Pin
Luc Pattyn31-Jan-10 5:03
sitebuilderLuc Pattyn31-Jan-10 5:03 

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.