C# Error CS0533 – ‘derived-class member’ hides inherited abstract member ‘base-class member’

C# Compiler Error

CS0533 – ‘derived-class member’ hides inherited abstract member ‘base-class member’

Reason for the Error

You’ll get this error in your C# code when your base class method is hidden.

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

using System;

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

    abstract public class ChildClass : ParentClass
    {
        new abstract public void Method1(); 
    }

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

The above program has a ParentClass with an abstract method Method1. The ChildClass inherits from the ParentClass but also has a method Method1 defined with the new keyword. This hides the base class’s method Method1 and C# compiler will throw the error code CS0533.

Error CS0533 ‘ChildClass.Method1()’ hides inherited abstract member ‘ParentClass.Method1()’ DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 12 Active

C# Error CS0533 – 'derived-class member' hides inherited abstract member 'base-class member'

Solution

To fix this error, you’ll need to override the method in the inherited class instead of hiding the base class method.

using System;

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

    abstract public class ChildClass : ParentClass
    {
	// This line replaced with override to fix the error code CS0533
        override abstract public 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...