Compiler Error CS0106 - C# reference (original) (raw)

The modifier 'modifier' is not valid for this item

A class or interface member was marked with an invalid access modifier. The following examples describe some of these invalid modifiers:

In prior releases of Visual Studio, the static modifier was not permitted on a class, but static classes are allowed starting with Visual Studio 2005.

For more information, see Interfaces.

Example

The following sample generates CS0106:

// CS0106.cs
namespace MyNamespace
{
   interface I
   {
      void M1();
      void M2();
   }

   public class MyClass : I
   {
      public readonly int Prop1 { get; set; }   // CS0106
      public int Prop2 { get; readonly set; }   // CS0106

      public void I.M1() {}   // CS0106
      abstract void I.M2() {}   // CS0106

      public void AccessModifierOnLocalFunction()
      {
         public void LocalFunction() {}   // CS0106
      }

      public readonly void ReadonlyMethod() {}   // CS0106
      // Move the `readonly` keyword after the `ref` keyword
      public readonly ref int ReadonlyBeforeRef(ref int reference)   // CS0106
      {
         return ref reference;
      }

      public static void Main() {}
   }

   public readonly class ReadonlyClass {}   // CS0106
}