C# Compiler Error
CS0133 – The expression being assigned to ‘variable’ must be constant
Reason for the Error
You will receive this error when you assign a static variable to a constant where variable is not of type “constant” in your C# code.
For example, try compiling the below C# code snippet.
namespace DeveloperPublishNamespace
{
public class DeveloperPublish
{
public const int i = j;
public static int j =10;
public static void Main()
{
}
}
}You will receive the error CS0133 because j (of type static int) is assigned to a constant i.
Error CS0133 The expression being assigned to ‘DeveloperPublish.i’ must be constant ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 5 Active
Solution
To fix the error code CS0133, ensure that the value that is assigned to a constant is constant as well.
