Compiler Error CS0070
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.
The following sample generates CS0070:
C#
// 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 Foo ()
{
EventHandler eh = new EventHandler(A.OnClick);
A a = new A();
eh = a.Click; // CS0070
// try the following line instead
// a.Click += eh;
return 1;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: