C# Error CS0738 – ‘{0}’ does not implement interface member ‘{1}’. ‘{2}’ cannot implement ‘{1}’ because it does not have the matching return type of ‘{3}’.

C# Error

CS0738 – ‘{0}’ does not implement interface member ‘{1}’. ‘{2}’ cannot implement ‘{1}’ because it does not have the matching return type of ‘{3}’.

Reason for the Error & Solution

‘type name’ does not implement interface member ‘member name’. ‘method name’ cannot implement ‘interface member’ because it does not have the matching return type of ‘ type name’.

The return value of an implementing method in a class must match the return value of the interface member that it implements.

To correct this error

  1. Change the return type of the method to match that of the interface member.

Example

The following code generates CS0738 because the class method returns void and the interface member of the same name returns int:

using System;  
  
interface ITest  
{  
    int TestMethod();  
}  
public class Test: ITest  
{  
    public void TestMethod() { } // CS0738  
    // Try the following line instead.  
    // public int TestMethod();  
}  

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...