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

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...