Monday, October 6, 2008

c# ambiguity names between method and event

Maybe some of you have already got to a dead end with ambiguity names, when trying to implement an interface where a method of the interface and an event have the same name, and we won't be able to catch the event triggered by the class.
Ambiguity means that the object of the class doesn't know how to distinguish which to use, because they have the same name, and the compiler will use the method instead of the event.
To get ride of the warning and the error associated with that, given by Visual Studio 2008 "Ambiguity between method and non-method . Using method group.", we need to do some cast inbetween.

The necessary cast will be to the Class of the Interface:
((InterfaceClassName) ourObject).InterfaceEventsName_Event_ EventName += new InterfaceEventsName_EventNameEventHandler(MethodNameToCall);

0 comments: