C# Error CS0549 – ‘function’ is a new virtual member in sealed class ‘class’

C# Compiler Error

CS0549 – ‘function’ is a new virtual member in sealed class ‘class’

Reason for the Error

You will get this error in your C# code when you define a virtual method is a class that is marked as sealed. When a class is marked as sealed, it means you cannot inherit from it. Technically, it cannot be used as base class.

For example, let’s compile the below C# program

using System;

namespace DeveloperPublishConsoleCore
{
    public sealed class Employee
    {
        // Results in the Error Code CS0549
        virtual public void GetEmployeeDetails()
        {

        }
    }

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

You will receive the error code CS0549 because the class Employee is marked as sealed and we are trying to have a virtual method in the sealed Employee class.

Error CS0549 ‘Employee.GetEmployeeDetails()’ is a new virtual member in sealed type ‘Employee’ DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 8 Active

C# Error CS0549 – 'function' is a new virtual member in sealed class 'class'

Solution

In C#, you cannot have a virtual method is a sealed class. To fix this error in your C# program, you’ll have to remove the sealed keyword for the class or don’t have a virtual method inside the sealed class.

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