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.

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...