HomeCSharpC# Error CS0205 – Cannot call an abstract base member: ‘method’

C# Error CS0205 – Cannot call an abstract base member: ‘method’

C# Compiler Error

CS0205 – Cannot call an abstract base member: ‘method’

Reason for the Error

You will receive this error in your C# program when you are trying to call an abstract method.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{
    abstract public class BaseEmployee
    {
        abstract public void SetId(int i);
    }

    public class Employee : BaseEmployee
    {
        public override void SetId(int i)
        {
            base.SetId(i); 
        }
    }
    class Program
    {
        static void Main()
        {

        }
    }

}

This program will result with the error code CS0205 because the method SetId() in BaseEmployee is abstract and we are attempting to call this function via base.SetId() from Employee class.

Error CS0205 Cannot call an abstract base member: ‘BaseEmployee.SetId(int)’ ConsoleApp3 C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 12 Active

Solution

To fix the error code CS0205, you should avoid calling the abstract method as they don’t have a method body.

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