Dela via


Kompilatorfel CS0507

"function1" : kan inte ändra åtkomstmodifierare vid åsidosättande av "åtkomst" ärvd medlem "function2"

Ett försök gjordes att ändra åtkomstspecifikationen i en åsidosättning av en metod.

Exempel 1

Följande exempel genererar CS0507.

// CS0507.cs  
abstract public class clx  
{  
   virtual protected void f() {}  
}  
  
public class cly : clx  
{  
   public override void f() {}   // CS0507  
   public static void Main() {}  
}  

Exempel 2

CS0507 kan också inträffa om en klass försöker åsidosätta en metod som har markerats som protected internal definierad i refererade metadata. I den här situationen bör den övergripande metoden markeras som protected.

// CS0507_b.cs  
// compile with: /target:library  
abstract public class clx  
{  
   virtual protected internal void f() {}  
}  

Följande exempel genererar CS0507.

// CS0507_c.cs  
// compile with: /reference:cs0507_b.dll  
public class cly : clx  
{  
   protected internal override void f() {}   // CS0507  
   // try the following line instead  
   // protected override void f() {}   // OK  
  
   public static void Main() {}  
}