C# Error CS0509 – ‘class1’ : cannot derive from sealed type ‘class2’

C# Compiler Error

CS0509 – ‘class1’ : cannot derive from sealed type ‘class2’

Reason for the Error

You’ll get this error in your C# code when you attempt to try to treat a sealed class as a base class and inherit from it.

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

C#

You’ll receive the error code CS0509 because the class BaseClass is marked as sealed and you are trying to inherit the ChildClass from the sealed base class.

Error CS0509 ‘ChildClass’: cannot derive from sealed type ‘BaseClass’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 8 Active

C# Error CS0509 – 'class1' : cannot derive from sealed type 'class2'

Solution

sealed classes in C# cannot act as a base class in C#. You will need to remove the sealed modifier if you need to inherit from this class. Also note that by default, structs in C# are sealed.

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