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' is never used
An event was declared but never used in the class in which it was declared.
Note
This warning is only reported during explicit Build or Rebuild operations. It does not appear during typing in the IDE as part of IntelliSense diagnostics. This means that if you fix the warning by using the field or removing it, the warning might persist in the error list until you build or rebuild the project again.
The following sample generates CS0067:
// CS0067.cs
// compile with: /W:3
using System;
delegate void MyDelegate();
class MyClass
{
public event MyDelegate evt; // CS0067
// uncomment TestMethod to resolve this CS0067
/*
private void TestMethod()
{
if (evt != null)
evt();
}
*/
public static void Main()
{
}
}
If the event is unused intentionally, for example, when it's part of an interface implementation, then you can avoid emitting an unnecessary field as follows:
using System;
public interface IThing
{
event Action? E;
}
public class Thing : IThing
{
// no CS0067 though the event is left unused
public event Action? E { add { } remove { } }
}