컴파일러 오류 CS0308
업데이트: 2007년 11월
오류 메시지
형식 인수에는 제네릭이 아닌 type-or-method 'identifier'을(를) 사용할 수 없습니다.
The non-generic type-or-method 'identifier' cannot be used with type arguments.
제네릭이 아닌 메서드 또는 형식을 형식 인수에 사용했습니다. 이 오류가 발생하지 않도록 하려면 꺾쇠괄호와 형식 인수를 제거하거나 메서드 또는 형식을 제네릭 메서드 또는 형식으로 다시 선언합니다.
다음 예제에서는 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];
}
}