title: How to cast object array to generic type array
body: <p>I am trying to cast an object array to generic object array in CSharp, keep getting this compiler error. Any ideas?</p>
  
  <p>Thanks</p>
  
  <pre><code> private const int INITIAL_CAPACITY = 20;
      protected int numElements;
      protected E[] elements;
  
      /*
       * default constructor that creates a new set
       * that is initially empty
       * */
      public ArraySet()
      {
          numElements = 0;
          elements = (E[])(new Object[INITIAL_CAPACITY]);// unchecked
      }
  </code></pre>
  
  <p>thanks guys, Another related question, I want to set a particular element to null. The following code does not work.</p>
  
  <p>elements[numElements - 1] = null:</p>
  
  <p>What is the correct null value we should use in here then. thank</p>