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

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