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

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