C# Error CS0539 – ‘member’ in explicit interface declaration is not a member of interface

C# Compiler Error

CS0539 – ‘member’ in explicit interface declaration is not a member of interface

Reason for the Error

You’ll get this error in your C# code when you are trying to explicitly declare an interface member that does not exist.

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

using System;

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

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

    class PermanentEmploee : IEmployee
    {
        void IEmployee.GetDetails()
        {
        }

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

In the above example, we are trying to explictly declare an interface member SetDate() in the PermanentEmploee that doesnot exist in the interface IEmployee. This will trigger the errorcode CS0539.

Error CS0539 ‘PermanentEmploee.SetDate()’ in explicit interface declaration is not found among members of the interface that can be implemented DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 23 Active

C# Error CS0539 – 'member' in explicit interface declaration is not a member of interface

Solution

To fix this error in your C# code, you will need to delete the declaration or else update the class to refer to a valid interface member.

using System;

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

    public class TempEmployee
    {
        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...