title: c# access elements of list passed as object type
body: <p>I want to access members of lists passed in as "object" (the function is handling other data types such as arrays as well). Unfortunately, while this works:</p>
  
  <pre><code>List&lt;object&gt; objectlist = new List&lt;object&gt; { "1", "2" };
  object res = ((List&lt;object&gt;)((object)objectlist))[0];
  </code></pre>
  
  <p>this does not:</p>
  
  <pre><code>List&lt;string&gt; strlist = new List&lt;string&gt; { "1", "2" };
  res = (string)((List&lt;object&gt;)((object)strlist))[0];
  </code></pre>
  
  <p>though it DOES work with arrays.</p>
  
  <p>It does not appear to be possible to convert regular lists to List. </p>
  
  <p>Is using reflection (but with GetMethods to avoid repeated string searches):</p>
  
  <pre><code>MethodInfo info = ((object)list).GetType().GetMethod("get_Item");
  object s1 = (object)info.Invoke(((object)list), new object[] { 0 });
  </code></pre>
  
  <p>the only way to do this?</p>