C# Error CS0106 – The modifier ‘modifier’ is not valid for this item

C# Compiler Error

CS0106 – The modifier ‘modifier’ is not valid for this item

Reason for the Error

You will receive this error when you have marked your class or interface with an invalid access modifier.

Take the below code snippet as an example.

abstract interface ITest
{
   public void M();
}

public class DeveloperPublish
{
    public static void Main()
    {

    }
}

You have an interface by the name ITest and you have prefixed it with the abstract keyword in the explicit interface declaration.

This will result in the CS0106 error.

C# Error CS0106 – The modifier 'modifier' is not valid for this item

Solution

To fix the above error, remove the abstract keyword from the explicit interface declaration.

There are plenty of other scenarios where you would encounter a similar scenario. For example, in the C# versions before C# 8.0 and when you have the public keyword defined on the explicit interface declaration, you will receive the same error.

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