C# Error CS0534 – ‘function1’ does not implement inherited abstract member ‘function2’

C# Compiler Error

CS0534 – ‘function1’ does not implement inherited abstract member ‘function2’

Reason for the Error

You’ll get this error in your C# code when you have not implemented all the abstract members of the base class especially when the inherited class is not an abstract class.

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

using System;

namespace DeveloperPublishConsoleCore
{
    namespace x
    {
        abstract public class BaseClass
        {
            public abstract void Method1();
        }

        public class ChildClass : BaseClass
        {

        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

In the above example, the Baseclass has an abstract method Method1. The childclass inherits from the Baseclass but you’ll notice that it doesnot implement the method Method1(). This will result in the C# error code CS0534 by the C# compiler.

Error CS0534 ‘ChildClass’ does not implement inherited abstract member ‘BaseClass.Method1()’ DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 12 Active

C# Error CS0534 – 'function1' does not implement inherited abstract member 'function2'

Solution

In C#, it is necessary for the class to implement all the abstract members that it is inheriting from the base class. The only exception is that the inherited/child class need not implement the abstract members if it is also abstract.

To fix this error, you’ll need to override or implement the abstract members.

using System;

namespace DeveloperPublishConsoleCore
{
    namespace x
    {
        abstract public class BaseClass
        {
            public abstract void Method1();
        }

        public class ChildClass : BaseClass
        {
            public override void Method1()
            {
            }
        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

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