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.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...