title: Class with a generic class composition that implement IComparable, C#
body: <p>I want to create a PQ that uses a separate class called Key to store the values that can take in a generic type, I also want to restrict the types to string and int. I will need to implement the IComparable interface. How do I do this? </p>
  
  <p>I am getting a bunch of errors regarding the type arguments, I have put comments in my code to show where the errors are.</p>
  
  <p>How do I implement something like this?</p>
  
  <pre><code>public class MaxPQ&lt;T&gt;
  {
      private Key[] pq; //Key requires 1 type argument
      private int N;
  
      public MaxPQ(int capacity)
      {
          pq = new Key[capacity + 1]; //Requires Type arguments
      }
  
  
      private void exch&lt;T&gt;(int i, int j)
      {
          Key&lt;T&gt; temp = pq[i]; //Cannot be used as a type
          pq[i] = pq[j];
          pq[j] = temp;
      }
  
  
  
      /// &lt;summary&gt;
      /// Key class for value in the Priority Queue
      /// &lt;/summary&gt;
      private class Key&lt;T&gt; where T : IComparable&lt;int, string&gt; //IComparable cannot be used with type argument
      {
          T _value;
  
          public Key(T value)
          {
              _value = value;
          }
  
  
          public int CompareTo(Key obj) //Required type arguments
          {
              if (obj == null) return 1;
  
              return;
          }
  
  
      }
  </code></pre>