C# Error CS0418 – ‘class name’: an abstract class cannot be sealed or static

C# Compiler Error

CS0418 – ‘class name’: an abstract class cannot be sealed or static

Reason for the Error

You’ll get this error in your C# code when you are trying to mark an abstract class as sealed.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    public abstract sealed class Employee  
    {
    }

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

You’ll receive the error code CS0418 when you compile the above C# program because you are using the using the sealed keyword on the abstract class. In C#, an abstract class cannot be used for instantiating unless you inherit or derive the abstract class. There won’t be any meaning if you are making the abstract class as sealed. The same applies for the abstract class marked as static as well.

Error CS0418 ‘Employee’: an abstract type cannot be sealed or static DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 5 Active

C# Error CS0418 – 'class name': an abstract class cannot be sealed or static

Solution

You can avoid this error in your C# code by ensuring that you don’t mark the abstract class as either sealed or static.

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