HomeCSharpC# Error CS0695 – ‘{0}’ cannot implement both ‘{1}’ and ‘{2}’ because they may unify for some type parameter substitutions

C# Error CS0695 – ‘{0}’ cannot implement both ‘{1}’ and ‘{2}’ because they may unify for some type parameter substitutions

C# Error

CS0695 – ‘{0}’ cannot implement both ‘{1}’ and ‘{2}’ because they may unify for some type parameter substitutions

Reason for the Error & Solution

‘generic type’ cannot implement both ‘generic interface’ and ‘generic interface’ because they may unify for some type parameter substitutions

This error occurs when a generic class implements more than one parameterization of the same generic interface, and there exists a type parameter substitution which would make the two interfaces identical. To avoid this error, implement only one of the interfaces, or change the type parameters to avoid the conflict.

The following sample generates CS0695:

// CS0695.cs  
// compile with: /target:library  
  
interface I<T>  
{  
}  
  
class G<T1, T2> : I<T1>, I<T2>  // CS0695  
{  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...