Compiler Error CS0504

Switch View :
ScriptFree
Visual Studio 2010 - Visual C#
Compiler Error CS0504

The constant 'variable' cannot be marked static

If a variable is const, it is also static. If you want a const and static variable, just declare that variable as const; if all you want is a static variable, just mark it static.

The following sample generates CS0504:

// CS0504.cs
namespace x
{
   abstract public class clx
   {
      static const int i = 0;   // CS0504, cannot be both static and const
      abstract public void f();
   }
}
Community Content

Pink Duck
Shouldn't this be a warning?
If 'static const' is equivalent to 'const' then why is this a compiler error?

If you need to bring attention to developers that a static variable might have ended up as a const then wouldn't a warning suffice?