title: The type T must be a reference type in order to use it as parameter while using interface
body: <p>I got the error for the below code</p>
  
  <pre><code>public static Moq.Mock&lt;T&gt; CreateInstanceOfIMock&lt;T&gt;() {
      return new Moq.Mock&lt;T&gt;();
  }
  </code></pre>
  
  <p>I have <a href="https://stackoverflow.com/questions/6451120/the-type-must-be-a-reference-type-in-order-to-use-it-as-parameter-t-in-the-gen/6451237"><em>solved</em></a> the error it by using referred <code>class</code> type. See this below code</p>
  
  <pre><code>public static Moq.Mock&lt;T&gt; CreateInstanceOfIMock&lt;T&gt;() where T : class
  {
      return new Moq.Mock&lt;T&gt;();
  }
  </code></pre>
  
  <hr>
  
  <p>Now I want to move this <code>var mockColorsRepository = new Moq.Mock&lt;IColorsRepository&gt;();</code> code into common code by using <code>generics</code>. here <code>IColorsRepository</code> is an <code>interface</code>. So I made an interface reference for <code>T</code> instead of <code>class</code> like this below code</p>
  
  <pre><code>public static Moq.Mock&lt;T&gt; CreateInstanceOfIMock&lt;T&gt;() where T : interface
  {
      return new Moq.Mock&lt;T&gt;();
  }
  </code></pre>
  
  <p>But am getting <code>The type T must be a reference type in order to use it as parameter</code> error. How can I refer <code>interface</code> instead of <code>class</code> to <code>T</code>. How can I achieve this?</p>