Errore del compilatore CS0308

Aggiornamento: novembre 2007

Messaggio di errore

Tipo o metodo 'identificatore' non generico non può essere utilizzato con argomenti di tipo.
The non-generic type-or-method 'identifier' cannot be used with type arguments.

Un tipo o un metodo non generico è stato utilizzato con argomenti di tipo. Per correggere l'errore, rimuovere le parentesi angolari e gli argomenti di tipo oppure dichiarare nuovamente il metodo o il tipo come generico.

Il seguente codice di esempio genera l'errore CS0308:

// CS0308a.cs
class MyClass
{
   public void F() {}
   public static void Main()
   {
      F<int>();  // CS0308 – F is not generic.
      // Try this instead:
      // F();
   }
}

Anche il seguente codice di esempio genera l'errore CS0308. Per correggere l'errore, utilizzare la direttiva "using System.Collections.Generic".

// CS0308b.cs
// compile with: /t:library
using System.Collections;
// To resolve, uncomment the following line:
// using System.Collections.Generic;
public class MyStack<T>
{
    // Store the elements of the stack:
    private T[] items = new T[100];
    private int stack_counter = 0;

    // Define the iterator block:
    public IEnumerator<T> GetEnumerator()   // CS0308
    {
        for (int i = stack_counter - 1 ; i >= 0; i--)
        yield return items[i];
    }
}