Errore del compilatore CS0616

Aggiornamento: novembre 2007

Messaggio di errore

'classe': non è una classe Attribute.
'class' is not an attribute class

È stato effettuato un tentativo di utilizzare una classe non attribute in un blocco di attributi. Tutti i tipi di attributo devono essere ereditati da System.Attribute.

Esempio

Il seguente codice di esempio genera l'errore CS0616.

// CS0616.cs
// compile with: /target:library
[CMyClass(i = 5)]   // CS0616
public class CMyClass {}

Il seguente codice di esempio mostra come definire un attributo:

// CreateAttrib.cs
// compile with: /target:library
using System;

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)]
public class MyAttr : Attribute
{
   public int Name = 0;
   public int Count = 0;

   public MyAttr (int iCount, int sName)
   {
      Count = iCount;
      Name = sName;
   }
}

[MyAttr(5, 50)]
class Class1 {}

[MyAttr(6, 60)]
interface Interface1 {}