更新: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];
}
}