C# Error CS0540 – ‘interface member’ : containing type does not implement interface ‘interface’

C# Compiler Error

CS0540 – ‘interface member’ : containing type does not implement interface ‘interface’

Reason for the Error

You’ll get this error in your C# code when you are trying to implement an member of interface in a class that does not inherit or derive from the interface.

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

using System;

namespace DeveloperPublishConsoleCore
{
    interface IEmployee
    {
        void GetDetails();
    }
    class PermanentEmployee
    {
        // Results in the Error code CS0540
        void IEmployee.GetDetails()
        {
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

In the above example, we are trying to derive an interface member GetDetails() in the PermanentEmployee class but the class itself does not derive from the interface.

Error CS0540 ‘PermanentEmployee.IEmployee.GetDetails()’: containing type does not implement interface ‘IEmployee’ DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 12 Active

C# Error CS0540 – 'interface member' : containing type does not implement interface 'interface'

Solution

To fix this error in your C# code, you will need to delete the interface member implementation or derive the class from the specified interface.

using System;

namespace DeveloperPublishConsoleCore
{
    interface IEmployee
    {
        void GetDetails();
    }

    public class TempEmployee : IEmployee
    {
        public void SetDate()
        {
        }
    }

    class PermanentEmploee : IEmployee
    {
        void IEmployee.GetDetails()
        {
        }
    }
    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...