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