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 -= (except when used from within the type 'type')
Outside of the class it is defined in, an event can only add or subtract references. For more information, see Events (C# Programming Guide).
The following sample generates CS0070:
// CS0070.cs
using System;
public delegate void EventHandler();
public class A
{
public event EventHandler Click;
public static void OnClick()
{
EventHandler eh;
A a = new A();
eh = a.Click;
}
public static void Main()
{
}
}
public class B
{
public int M ()
{
EventHandler eh = new EventHandler(A.OnClick);
A a = new A();
eh = a.Click; // CS0070
// try the following line instead
// a.Click += eh;
return 1;
}
}