Compiler Warning (level 3) CS0067
The event 'event' is never used
An event was declared but never used in the class in which it was declared.
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()
{
}
}
Re: "Restore" vs. "Enable"
Will,
I can only guess here, but the use of "restore" vs. "enable" can make sense in the case where the warning could have been disabled globally. In that case, you really are restoring to the global setting, not simply enabling the warning regardless of whether any global suppression might be in force. So "restore" here really has the correct meaning, while "enable" would not be truly accurate.
-- Mike
- 1/3/2010
- Mike Rosenblum
How to suppress this message
This message can be incredibly annoying when creating APIs. To suppress, place #pragma's before and after to turn off and turn back on this compiler warning.
For example:
#pragma warning disable 0067
public event EventHandler<EventArgs> ThisEventIsNeverUsedLol;
#pragma warning restore 0067
The compiler will ignore this error for this particular event but for no other event in the solution.
Also, please note it is "disable" and "restore", not "enable". Good job, compiler team!
- 12/20/2007
- Will Sullivan
- 12/20/2007
- Will Sullivan