• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Delegates in C#

A delegate is there in a object.

Event += new EventHandler(fun 1);
Event += new EventHandler(fun 2);

In this case I dont want fun 2 to run. My function is fun1.
Is there any way to remove fun 2 from the delegate event.
0
Ashok9
Asked:
Ashok9
  • 3
  • 2
5 Solutions
 
Jon500Commented:
Yes, use:

Event -= fun2;

Regards,
Jon500
0
 
Ashok9Author Commented:
But it can be used only if that fun2 is added in the same context. But The fun2 is added in other class. I can not touch that code.
0
 
Jon500Commented:
I really don't have all the information from your original question so it really is quite difficult to know the constraints of your issue.

Can you subclass the object in question and override the event-handler function without calling the base-class function?

Regards,
Jon500
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
roeibCommented:
why dont you add a the fun2 event to a different delegate then you  can control each one of them individually
0
 
Jon500Commented:
@roeib: I think what he's saying is that the event delegates are being assigned in some third-party object and he cannot change these already-assigned delegates. I think he is asking if there is a way to remove an event handler declared in a class library...

At least that's what I think he's asking!... Author? What say you???

Jon500
0
 
roeibCommented:
@Jon500: thats an excellent question, cause if thats the case he needs to access the base and override just like you commented. i do agree that seeing the code would make it a lot easier to understand the problem
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now