Edit

Share via


Compiler Warning (level 2) CS0278

'type' does not implement the 'pattern name' pattern. 'method name' is ambiguous with 'method name'.

There are several statements in C# that rely on defined patterns, such as foreach and using. For example, the foreach statement relies on the collection class implementing the "enumerable" pattern.

CS0278 can occur if the compiler is unable to make the match due to ambiguities. For example, the "enumerable" pattern requires that there be a method called MoveNext, and your code might contain two methods called MoveNext. The compiler will attempt to find an interface to use, but it is recommended that you determine and resolve the cause of the ambiguity.

Example

The following sample generates CS0278.

C#
// CS0278.cs  
using System.Collections.Generic;  
public class myTest
{  
   public static void TestForeach<W>(W w)
      where W: IEnumerable<int>, IEnumerable<string>  
   {  
      foreach (int i in w) {}   // CS0278  
   }  
}