Skip to content

Commit

Permalink
Update CS0110 (#39749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rageking8 authored Feb 29, 2024
1 parent 0e1f9dd commit ed11014
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions docs/csharp/misc/cs0110.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
---
description: "Compiler Error CS0110"
title: "Compiler Error CS0110"
ms.date: 07/20/2015
f1_keywords:
ms.date: 02/29/2024
f1_keywords:
- "CS0110"
helpviewer_keywords:
helpviewer_keywords:
- "CS0110"
ms.assetid: 0bfe7071-1194-4142-a1a1-6190ee92b1d4
---
# Compiler Error CS0110

The evaluation of the constant value for 'const declaration' involves a circular definition

The declaration of a [const](../language-reference/keywords/const.md) variable (`a`) cannot reference another const variable (`b`) that also references (`a`).

The following sample generates CS0110:

```csharp
// CS0110.cs
namespace MyNamespace
{
public class A
{
public static void Main()
{
}
}

public class B : A
{
public const int i = c + 1; // CS0110, c already references i
public const int c = i + 1;
// the following line would be OK
// public const int c = 10;
}
}
```

The evaluation of the constant value for 'const declaration' involves a circular definition

The declaration of a [const](../language-reference/keywords/const.md) variable cannot reference another const variable such that a circular dependency is formed. This also applies to associated constant values of enum members.

## Example

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:

```csharp
// 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.

## See also

- [Constants](../programming-guide/classes-and-structs/constants.md)

0 comments on commit ed11014

Please sign in to comment.