C# Error CS0543 – ‘enumeration’ : the enumerator value is too large to fit in its type

C# Compiler Error

CS0543 – ‘enumeration’ : the enumerator value is too large to fit in its type

Reason for the Error

You will get this error in your C# code when an value assigned to the enum in outside the range of the data type that it is defined.

For example, let’s compile the below C# program

using System;

namespace DeveloperPublishConsoleCore
{
    enum EMPLOYEETYPE : short
    {
        FullType = 32766, 
        PartTime,
        Contract // CS0543 
    }   

    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

You will receive the error code CS0543 because the enum allows you to have values upto 32767 because the range of the data type is short. We have assigned the enum FullType, a value of 32766. The code fails when you define the enum Contract.

Error CS0543 ‘EMPLOYEETYPE.Contract’: the enumerator value is too large to fit in its type DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 9 Active

C# Error CS0543 – 'enumeration' : the enumerator value is too large to fit in its type

Solution

To fix this error in your C# program, ensure that the value that is assigned to the element in the enum is with-in the range of the data type.