title: C#: System.Object vs Generics
body: <p>I'm having a hard time understanding when to use Object (boxing/unboxing) vs when to use generics.</p>
  
  <p>For example:</p>
  
  <pre><code>public class Stack 
  {
      int position;
      object[] data = new object[10];
      public void Push (object o) { data[position++] = o; }
      public object Pop() { return data[--position]; }
  }
  </code></pre>
  
  <p>VS.</p>
  
  <pre><code>public class Stack&lt;T&gt;
  { 
    int position; 
    T[] data = new T[100]; 
    public void Push(T obj)  {data[position++] = obj; }
    public T Pop() { return data[--position]; }
   }
  </code></pre>
  
  <p>Which one should I use and under what conditions? It seems like with the System.Object way I can have objects of all sorts of types currently living within my Stack. So wouldn't this be always preferable? Thanks!</p>