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

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...