C# Error CS0275 – ‘accessor’: accessibility modifiers may not be used on accessors in an interface

Compiler Error

CS0275 – ‘accessor’: accessibility modifiers may not be used on accessors in an interface

Reason for the Error

You’ll get this error in your C# code when you try to use an access modifier on any of the accessors of the property in an interface.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPublishNamespace
{
    public interface IEmployee
    {
        int Id
        {
            get;
            internal set;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0275 because you have specified the access modifier internal for the set accessor in the IEmployee interface.

CS0275 – ‘accessor’: accessibility modifiers may not be used on accessors in an interface ‘Employee.Id’ DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 9 Active

C# Error CS0275 – 'accessor': accessibility modifiers may not be used on accessors in an interface

Solution

You can fix this error in your C# program by removing the access modifier as shown below. Also note that if you are using the latest version of C# (For example : C# 8, you’ll not see this error).

using System;

namespace DeveloperPublishNamespace
{
    public interface IEmployee
    {
        int Id
        {
            get;
            set;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("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...