Can we add an event handler that has different delegate?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

As topic,

Can we add an event handler that has different delegate?

Example:

I have a method that takes no parameter:
public void xyz()

I would like button1 to fire that method onclick.
button1.Click += new EventHandler(xyz)

I understand that button click event should has parameter like this :
(object sender, System.EventArgs e)

But what if I want to "force" it add the method? Or at least maybe make a
convert on runtime, like convert xyz() to xyz(object sender,
System.EventArgs e), and pass in (null, null).

Can I achieve that?


Thanks,
Tee
 
Why not just overload it?
xyz(object sender, System.EventArgs e)
{
xyz(null, null)
}

xyz()
{
.....
}
Chris
 
Short answer... No. Delegates are type safe, so they encforce the rule
that any function passed to the delegate has to implement the exact
signature. You will have to wait for anonymous methods in 2.0 to
achieve something like what you want.

In anycase, i dont see the reason why this functionality would be
required.

NuTcAsE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top