Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The event 'event' can only appear on the left hand side of += or -=
An event was called incorrectly. For more information, see Events (C# Programming Guide) and Delegates (C# Programming Guide).
The following sample generates CS0079:
// CS0079.cs
using System;
public delegate void MyEventHandler();
public class Class1
{
private MyEventHandler _e;
public event MyEventHandler Pow
{
add
{
_e += value;
Console.WriteLine("in add accessor");
}
remove
{
_e -= value;
Console.WriteLine("in remove accessor");
}
}
public void Handler()
{
}
public void Fire()
{
if (_e != null)
{
Pow(); // CS0079
// try the following line instead
// _e();
}
}
public static void Main()
{
Class1 p = new Class1();
p.Pow += new MyEventHandler(p.Handler);
p._e();
p.Pow += new MyEventHandler(p.Handler);
p._e();
p._e -= new MyEventHandler(p.Handler);
if (p._e != null)
{
p._e();
}
p.Pow -= new MyEventHandler(p.Handler);
if (p._e != null)
{
p._e();
}
}
}