コンパイラ エラー CS0308
更新 : 2007 年 11 月
エラー メッセージ
非ジェネリック型または非ジェネリック メソッド '識別子' は型引数と一緒には使用できません。
ジェネリックではないメソッドまたは型で、型引数が使用されています。このエラーを回避するには、そのメソッドまたは型から、山かっこおよび型引数を削除するか、ジェネリック メソッドまたはジェネリック型として宣言し直します。
次の例では、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];
}
}