title: C# Generic contains Generic
body: <p>Is a way to change where constraint for generic class containing generic member to avoid constructions like this: </p>
  
  <pre><code>var _queue = new CommunicationQueue&lt;DataTag&lt;Messages&gt;, Messages&gt;(10);
  //this is what I would like:
  //var _queue = new CommunicationQueue&lt;DataTag&lt;Messages&gt;&gt;(10);
  
  public class CommunicationQueue&lt;TU, T&gt; where TU : DataTag&lt;T&gt;, new()
                                         where T : struct
  {
     private readonly ConcurrentQueue&lt;TU&gt; _queue;
     public int Limit { get; }
  
     public CommunicationQueue(int queueSize)
     {
         Limit = queueSize;
         _queue = new ConcurrentQueue&lt;TU&gt;();
     }
  
     internal void AddItem(T item)
     {
        _queue.Enqueue(new TU { RowData = item });
         while (_queue.Count &gt; Limit)
         {
            TU removed;
            _queue.TryDequeue(out removed);
         }
     }
  
     public IEnumerable&lt;TU&gt; GetLatestItems()
     {
        return _queue.Reverse().Take(Limit).ToArray();
     }
  }
  
   public class DataTag&lt;T&gt; where T : struct 
   {
       public DateTime Time { get; set; }   
  
       public T RowData { get; set;}
  
       public DataTag()
       {
           Time = DateTime.Now;
       }
  
       public DataTag(T rowData) : this()
       {
           RowData = rowData;
       }
   }
  
  public struct Messages
  {
      string Name { get; set; }
      ...
  }
  </code></pre>
  
  <p>Now to create a queue I should write:</p>
  
  <pre><code>var _queue = new CommunicationQueue&lt;DataTag&lt;Messages&gt;, Messages&gt;(10);
  </code></pre>
  
  <p>But this is what I would like:</p>
  
  <pre><code>var _queue = new CommunicationQueue&lt;DataTag&lt;Messages&gt;&gt;(10);
  </code></pre>