Share via


컴파일러 경고(수준 2) CS0279

업데이트: 2007년 11월

오류 메시지

'type name'은(는) 'pattern name' 패턴을 구현하지 않습니다. 'method name'은(는) public이 아니거나 static입니다.
'type name' does not implement the 'pattern name' pattern. 'method name' is either static or not public.

C#에는 foreach 및 using 같이 정의된 패턴에 의존하는 몇 가지 문이 있습니다. 예를 들어, foreach는 열거 가능한 패턴을 구현하는 컬렉션 클래스에 의존합니다. 이 오류는 public이 아니거나 static으로 선언된 메서드로 인해 컴파일러에서 일치시킬 수 없는 경우에 발생합니다. 패턴의 메서드는 클래스의 인스턴스이고 public이어야 합니다.

예제

다음 예제에서는 CS0279 오류가 발생하는 경우를 보여 줍니다.

// CS0279.cs

using System;
using System.Collections;

public class myTest : IEnumerable
{
    IEnumerator IEnumerable.GetEnumerator()
    {
        yield return 0;
    }

    internal IEnumerator GetEnumerator()
    {
        yield return 0;
    }

    public static void Main()
    {
        foreach (int i in new myTest()) {}  // CS0279
    }
}