Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

C# Error CS0441 – ‘class’: a class cannot be both static and sealed

C# Compiler Error

CS0441 – ‘class’: a class cannot be both static and sealed

Reason for the Error

You’ll get this error in your C# code when you declare a class as both static and sealed.

For example, let’s try to compile the below C# code snippet.

using System;
namespace DeveloperPublishNamespace
{
    sealed static class Employee 
    {

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

You’ll receive the error code CS0441 when you build the above C# code because you have declared the class Employee as both sealed and static.

Error CS0441 ‘Employee’: a type cannot be both static and sealed DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 4 Active

C# Error CS0441 – 'class': a class cannot be both static and sealed

Solution

The static classes in C# are inherently sealed by nature. You’ll not need the sealed modifier for the static classes.

You can fix this error in your C# program by using either static or sealed modifier and NOT both.