C# Error CS0513 – ‘function’ is abstract but it is contained in nonabstract class ‘class’

C# Compiler Error

CS0513 – ‘function’ is abstract but it is contained in nonabstract class ‘class’

Reason for the Error

You’ll get this error in your C# code when you declare an abstract member in a non-abstract class.

For example, let’s try to compile the below C# code snippet.

using System;
namespace DeveloperPublishNamespace
{
    public class BaseClass
    {
        abstract public void Function1();
    }

    class Program
    {
      
        static void Main(string[] args)
        {
            Console.WriteLine("No Error");
        }
    }
}

You’ll receive the error code CS0513 because the class BaseClass is a non-abstract class but you have declared an abstract function “Function1”.

Error CS0513 ‘BaseClass.Function1()’ is abstract but it is contained in non-abstract type ‘BaseClass’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 6 Active

C# Error CS0513 – 'function' is abstract but it is contained in nonabstract class 'class'

Solution

In C#, a method cannot be an abstract member in a non-abstract class. You’ll need to either make the class abstract or else remove the abstract declaration from the non-abstract class.

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