Share via


Compiler Error CS0546

'accessor' : cannot override because 'property' does not have an overridable set accessor

An attempt to override one of the accessor methods for a property failed because the accessor cannot be overridden. This error can occur if:

  • the base class property is not declared as virtual.

  • the base class property does not declare the get or set accessor you are trying to override.

If you do not want to override the base class property, you can use the new keyword before the property in derived class.

For more information, see Using Properties (C# Programming Guide).

Example

The following sample generates CS0546 because the base class does not declare a set accessor for the property.

// CS0546.cs
// compile with: /target:library
public class a
{
   public virtual int i
   {
      get
      {
         return 0;
      }
   }

   public virtual int i2
   {
      get
      {
         return 0;
      }

      set {}
   }
}

public class b : a
{
   public override int i
   {
      set {}   // CS0546 error no set
   }

   public override int i2
   {
      set {}   // OK
   }
}

See Also

Reference

Properties (C# Programming Guide)

Change History

Date

History

Reason

October 2008

Added text and code comments.

Customer feedback.