title: Convert object to List<int>
body: <p>I have stored List of int in a object type and I am trying to convert object to List of int using below code. Every time, it throws a casting exception.</p>
  <pre class="lang-cs prettyprint-override"><code>List&lt;int&gt; ObjToList(object array)
  {
      try
      {
          List&lt;object&gt; list = new List&lt;object&gt;();
          var enumerator = ((IEnumerable)array).GetEnumerator();
          while (enumerator.MoveNext())
          {
              list.Add(enumerator.Current);
          }
          var val = list.Cast&lt;int&gt;().ToList();
          return val;
      }
      catch (Exception ex)
      {
          return new List&lt;int&gt;();
      }
  }
  </code></pre>