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.Error
can 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.Error
can 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:
public delegate void MyClassEHandler(MyClassEParam param);
public static event MyClassEHandler Error
{
add
{
MyClassE.Error += value;
}
remove
{
MyClassE.Error -= value;
}
}
and the Delegate.Combine
will work magically for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With