C# Error CS0112 – A static member ‘function’ cannot be marked as override, virtual or abstract

C# Compiler Error

CS0112 – A static member ‘function’ cannot be marked as override, virtual or abstract

Reason for the Error

You will receive this error when you use the static keyword along with any of these keywords for the function definition.

  • override
  • virtual
  • abstract

For example, the below code snippet demonstrates the error CS0112 where the overridden method Function1 also contains the keyword static.

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

    }
}

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

C# Error CS0112 – A static member 'function' cannot be marked as override, virtual or abstract

Solution

To fix the above error, remove the static keyword on the methods that have override , virtual or abstract.

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