更新:2007 年 11 月
错误消息
“type name”不实现“pattern name”模式。“method name”是静态的或不是公共的。
在 C# 中有几个依赖于已定义模式的语句,例如 foreach 和 using。例如,foreach 依赖于实现枚举模式的集合类。当由于一个方法被声明为 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
}
}