Compiler Error CS0072
'event' : cannot override; 'method' is not an event
An event can only override another event. For more information, see Events.
Example
The following sample generates CS0072:
// CS0072.cs
delegate void MyDelegate();
class Test1
{
public virtual event MyDelegate MyEvent;
public virtual void VMeth()
{
}
public void FireAway()
{
if (MyEvent != null)
MyEvent();
}
}
class Test2 : Test1
{
public override event MyDelegate VMeth // CS0072
// Uncomment the following lines to resolve.
// public override event MyDelegate MyEvent
{
add
{
VMeth += value;
// MyEvent += value;
}
remove
{
VMeth -= value;
// MyEvent -= value;
}
}
public static void Main()
{
}
}
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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for