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.
LVL 5
Ashok9Asked:
Who is Participating?
 
Jon500Connect With a Mentor Commented:
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
 
Jon500Connect With a Mentor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
roeibConnect With a Mentor Commented:
why dont you add a the fun2 event to a different delegate then you  can control each one of them individually
0
 
Jon500Connect With a Mentor Commented:
@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
 
roeibConnect With a Mentor Commented:
@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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.