Compiler Error CS0110
The evaluation of the constant value for 'const declaration' involves a circular definition
The declaration of a const variable cannot reference another const variable such that a circular dependency is formed. This also applies to associated constant values of enum members.
The associated constant value of MyClass.Color.Red
is explicitly set to MyClass.Color.Blue
, but the value of MyClass.Color.Blue
is dependent on the previous enum member (MyClass.Color.Red
), hence both constant values cannot be determined. Similarly, the constant variable MyClass.a
is defined in terms of MyClass.b
, but that is also defined in terms of MyClass.a
.
The following sample generates CS0110:
// CS0110.cs
// compile with: /target:library
class MyClass
{
enum Color
{
Red = Blue, // CS0110
Blue,
}
public const int a = b + 1; // CS0110
public const int b = a + 1;
}
To resolve this error, break the circular reference by modifying or removing the definition.
.NET feedback
.NET is an open source project. Select a link to provide feedback: