When I try to define accessors for this event, the event invocation
line stops compiling. What's wrong?
public class TestClass
{
public delegate int MyDelegate(stri ng s);
public event MyDelegate myEvent
{
add { Console.WriteLi ne("myEvent.Add "); }
remove { Console.WriteLi ne("myEvent.Rem ove"); }
}
public void Foo(object sender, System.EventArg s e)
{
myEvent("event" ); // Compiler error: The event can only
// appear on the left hand side of += or -=
}
}
line stops compiling. What's wrong?
public class TestClass
{
public delegate int MyDelegate(stri ng s);
public event MyDelegate myEvent
{
add { Console.WriteLi ne("myEvent.Add "); }
remove { Console.WriteLi ne("myEvent.Rem ove"); }
}
public void Foo(object sender, System.EventArg s e)
{
myEvent("event" ); // Compiler error: The event can only
// appear on the left hand side of += or -=
}
}
Comment