共用方式為


編譯器錯誤 CS0308

更新:2007 年 11 月

錯誤訊息

非泛型型別或方法 'identifier' 不能配合型別引數使用。

方法或型別不屬於泛型,卻配合型別引數使用。若要避免這個錯誤,請移除角括弧及型別引數,或將方法或型別重新宣告為泛型方法或型別。

下列範例會產生 CS0308:

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

下列範例也會產生 CS0308。若要解決這個錯誤,請使用指示詞 "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];
    }
}