title: Extension Method for a List
body: <p>I have a List of a class Order which implements IComparable and override the Tostring method</p>
  
  <p><strong>Order class:</strong></p>
  
  <pre><code>public class Order : IComparable
      {
          public int id { get; set; }
          public DateTime date { get; set; }
          public int CompareTo(object obj)
          {
              if (obj == null)
              {
                  return 1;
              }
              else
              {
                  Order order = obj as Order;
                  if (order == null)
                  {
                      throw new ArgumentException("object is not an order");
                  }
                  return this.date.CompareTo(order.date);
              }
          }
          public override string ToString()
          {
              return this.id+"--"+this.date.ToString("dd/MM/yyyy");
          }
      }
  </code></pre>
  
  <p>Now i added an extension Method <em>Show</em> to List and it is working as i expected</p>
  
  <p><strong>Extension Class</strong></p>
  
  <pre><code>public static class ListExtension
  
      {
          public static void Show(this List&lt;Order&gt; list)
          {
  
              foreach (var item in list)
              {
                  Console.WriteLine(item.ToString());
              }
          }
      }
  </code></pre>
  
  <p>Now i would like to turn my method Show Generic :</p>
  
  <pre><code> public static class ListExtension&lt;T&gt;
     {
          public static void Show(this List&lt;T&gt; list)
          {
  
              foreach (var item in list)
              {
                  Console.WriteLine(item.ToString());
              }
          }
      }
  </code></pre>
  
  <p>But i can not call  the generic extension method. Can you help me .</p>