title: c# - How to implement a non generic interface in a generic class with constraints
body: <p>Here is my code:</p>
  
  <pre><code>public interface ICar
  {
      CarModel Property { get; set; }
      CarModel Method();
  }
  
  public Car&lt;T&gt; : ICar where T : CarModel 
  {
      T Property { get; set; }
      T Method()
      {
          //Do Stuff
      }
  }
  </code></pre>
  
  <p>I have implemented the interface in my <code>Car&lt;T&gt;</code> class with generic constraints but it doesn't compile with the following error:</p>
  
  <pre><code>Compilation error (line 18, col 15): 'Car&lt;T&gt;' does not implement interface member 'ICar.Property'. 'Car&lt;T&gt;.Property' cannot implement 'ICar.Property' because it does not have the matching return type of 'CarModel'.
  Compilation error (line 18, col 15): 'Car&lt;T&gt;' does not implement interface member 'ICar.Method()'. 'Car&lt;T&gt;.Method()' cannot implement 'ICar.Method()' because it does not have the matching return type of 'CarModel'.
  </code></pre>
  
  <p>I also need the interface to be non generic, here is a .Net fiddle: <a href="https://dotnetfiddle.net/m1jDnB" rel="nofollow">https://dotnetfiddle.net/m1jDnB</a></p>
  
  <p>The only work around I have for this is to wrap the property or method with something that implements the interface as it wants it BUT I dont want to do this. ie:</p>
  
  <pre><code>public Car&lt;T&gt; : ICar where T : CarModel 
  {
      T Property { get; set; }
      T Method()
      {
          //Do Stuff
      }
  
      CarModel ICar.Property 
      { 
        get {return Property; }
        set {Property = (CarModel)value; }
      }
  
      CarModel ICar.Method()
      {
          return (CarModel)Method();
      }
  }
  </code></pre>
  
  <p>Is there a better way?</p>