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

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