title: c# generic method
body: <p>I have a method that receives messages from a queue of msmq.</p>
  
  <p>I have 6 different queues in msmq and i d like a single generic method that would receive the messages. THis work, but i need to write 6 methods for each queue. I d like to make it more generic.</p>
  
  <pre><code>public List&lt;QueMessage&gt; getMessagesFromObj1Queue()
  {
      List&lt;QueMessage&gt; messageList = new List&lt;QueMessage&gt;();
  
      QueObj1 que = new QueObj1();
  
      while (que.ReceiveAll().Count &gt; 0)
      {
          varmessage = que.Receive(new TimeSpan(0, 1, 0));
          messageList.Add(message);
      }
  
      return messageList;
  }
  </code></pre>
  
  <p>I have 5 different object which just extends a single abstract class. Below doenst work.</p>
  
  <pre><code>public List&lt;QueMessage&gt; getMessagesFromObj1Queue&lt;T&gt;(T que)
  {
      List&lt;QueMessage&gt; messageList = new List&lt;QueMessage&gt;();
  
      while (que.ReceiveAll().Count &gt; 0)
      {
          varmessage = que.Receive(new TimeSpan(0, 1, 0));
          messageList.Add(message);
      }
  
      return messageList;
  }
  </code></pre>
  
  <p>Above doesnt work</p>
  
  <p>how to fix this?</p>