C# Error CS0113 – A member ‘function’ marked as override cannot be marked as new or virtual

C# Compiler Error

CS0113 – A member ‘function’ marked as override cannot be marked as new or virtual

Reason for the Error

You will receive this error when you have used both the new and the override keyword for the method declaration.

In C#, the new and the override keyword are mutually exclusive.

abstract public class Class1
{
    public abstract void Function1();
}
public class Class2 : Class1
{
    override new public void Function1()  
    {
    }
}
public class DeveloperPublish
{
    public static void Main()
    {

    }
}

In the above code the new and override keyword is used on the function Function1 and hence you will receive the error as shown below.

Error CS0113 A member ‘Class2.Function1()’ marked as override cannot be marked as new or virtual ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 7 Active

Solution

To fix the above error, remove the new keyword when using the override.

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