title: How to resolve boxing or conversion error for below example?
body: <p>In the code below;</p>
  <pre><code>CustomClass&lt;EnType1&gt; a = new CustomClass&lt;EnType1&gt;();
  CustomClass&lt;TEnum&lt;EnType1&gt;&gt; b = new CustomClass&lt;TEnum&lt;EnType1&gt;&gt;();
  </code></pre>
  <p>Throws error</p>
  <blockquote>
  <p>The type <code>ConsoleApp2.TEnum&lt;ConsoleApp2.EnType1&gt;</code> cannot be used as type parameter <code>T</code> in the generic type or method <code>CustomClass&lt;T&gt;</code>. There is no implicit reference conversion from <code>ConsoleApp2.TEnum&lt;ConsoleApp2.EnType1&gt;</code> to <code>System.Enum</code>.  and  The type <code>ConsoleApp2.EnType1</code> cannot be used as type parameter <code>T</code> in the generic type or method <code>CustomClass&lt;T&gt;</code>. There is no boxing conversion from <code>ConsoleApp2.EnType1</code> to <code>ConsoleApp2.IEnum</code>.</p>
  </blockquote>
  <p>How do I resolve this?</p>
  <p>Basically I want to create a generic class which I should be able to use any Enum and then any class that inherits from <code>IEnum</code></p>
  <p>Any help appreciated</p>
  <p>Full Code:</p>
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          CustomClass&lt;EnType1&gt; a = new CustomClass&lt;EnType1&gt;();
          CustomClass&lt;TEnum&lt;EnType1&gt;&gt; b = new CustomClass&lt;TEnum&lt;EnType1&gt;&gt;();
  
          TEnum&lt;EnType2&gt; t = new TEnum&lt;EnType2&gt;(EnType2.B);
          Console.WriteLine(&quot;Hello World!&quot; + t.EnumValue);
      }
  }
  </code></pre>
  <p>In this generic class I should be able to use any Enum and then any class that inherits from IEnum</p>
  <pre><code>public class CustomClass&lt;T&gt; where T : Enum, IEnum
  {
      public T Enum;
  }
  
  enum EnType1
  {
      A = 2,
      B = 3
  }
  
  enum EnType2
  {
      A = 0,
      B = 1
  }
  
  public interface IEnum
  {
      public int EnumValue { get; set; }
  }
  
  public class TEnum&lt;T&gt; : IEnum
  {
      public TEnum(T enumVal)
      {
          EnumValue = (int)(object)enumVal;
      }
      public int EnumValue { get ; set ; }
  }
  </code></pre>