Edit

Share via


Compiler Error CS0609

Cannot set the IndexerName attribute on an indexer marked override

The name attribute (IndexerNameAttribute) cannot be applied to an indexed property that is an override. For more information, see Indexers.

The following sample generates CS0609:

// CS0609.cs
using System;
using System.Runtime.CompilerServices;

public class idx
{
   public virtual int this[int iPropIndex]
   {
      get
      {
         return 0;
      }
      set
      {
      }
   }
}

public class MonthDays : idx
{
   [IndexerName("MonthInfoIndexer")]   // CS0609, delete to resolve this CS0609
   public override int this[int iPropIndex]
   {
      get
      {
         return 0;
      }
      set
      {
      }
   }
}

public class test
{
   public static void Main(string[] args)
   {
   }
}

Note

This compiler error is no longer used in Roslyn. The previous code should compile successfully.