Compiler Error CS0071
An explicit interface implementation of an event must use event accessor syntax
When explicitly implementing an event that was declared in an interface, you must manually provide the add
and remove
event accessors that are typically provided by the compiler. The accessor code can connect the interface event to another event in your class (shown later in this topic) or to its own delegate type. For more information, see How to implement interface events.
Example
The following sample generates CS0071.
// CS0071.cs
public delegate void MyEvent(object sender);
interface ITest
{
event MyEvent Clicked;
}
class Test : ITest
{
event MyEvent ITest.Clicked; // CS0071
// Try the following code instead.
/*
private MyEvent clicked;
event MyEvent ITest.Clicked
{
add
{
clicked += value;
}
remove
{
clicked -= 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