I got CS0079 compile error when I tried to run the code below:
public delegate void MyClassEHandler(MyClassEParam param);
public class MyClassE
{
public static event MyClassEHandler Error
{
add
{
MyClassE.Error = (MyClassEHandler)Delegate.Combine(MyClassE.Error, value);
}
}
}
Error:
CS0079 : The event
MyClassE.Errorcan only appear on the left hand
side of += or -=
Searched around but couldn’t figure out how to resolve it.
ADDED:
if (MyClass.Error != null) or
MyClass.Error(null, null);
Get the same CS0079 error.
CS0079 : The event
MyClassE.Errorcan only appear on the left hand
side of += or -=
Can anyone help me on this?
You cannot set an event, you can just add or remove handlers on it. So, as the error says, you should just do:
and the
Delegate.Combinewill work magically for you.