B
Brad Williams
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(string s);
public event MyDelegate myEvent
{
add { Console.WriteLine("myEvent.Add"); }
remove { Console.WriteLine("myEvent.Remove"); }
}
public void Foo(object sender, System.EventArgs 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(string s);
public event MyDelegate myEvent
{
add { Console.WriteLine("myEvent.Add"); }
remove { Console.WriteLine("myEvent.Remove"); }
}
public void Foo(object sender, System.EventArgs e)
{
myEvent("event"); // Compiler error: The event can only
// appear on the left hand side of += or -=
}
}