I am reverse-engineering a legacy application that is no longer supported and has stopped working so I can create a new one to perform the same function. I have this class that uses the following code pattern quite a lot.
public event myEventHandler myEvent
{
[MethodImpl(MethodImplOptions.Synchronized)]
add
{
myEvent = (myEventHandler)Delegate.Combine(myEvent, value);
}
[MethodImpl(MethodImplOptions.Synchronized)]
remove
{
myEvent = (myEventHandler)Delegate.Remove(myEvent, value);
}
}
However, Visual Studio returns the error:
"myEvent can only appear on the left-hand side of += or -="
Does the following code to solve this error? Is there any difference between delegate.combine and using +=
?
public event myEventHandler myEvent
{
[MethodImpl(MethodImplOptions.Synchronized)]
add
{
myEvent += value;
}
[MethodImpl(MethodImplOptions.Synchronized)]
remove
{
myEvent -= value;
}
}