title: C#: Why does dynamic help determine type argument for use in generic methods?
body: <p>I'm working with reflection to create some meta-tests to ensure equality between two instances of the same type.
  As such, I'm using a lot of vars and generics.
  One thing I've noticed is that with my generic functions, sometimes the Type argument is object (presumably when it can't determine the type) and other times it's the correct type.</p>
  <p>Example:</p>
  <p>Generic methods</p>
  <pre><code>public static RT[] CreateArrayWithNumItems&lt;RT&gt;(RT baseArgument, int numItems)
  {
      var a = new List&lt;RT&gt;();
      for (int i = 0; i &lt; numItems; i++)
      a.Add((RT)DataObjectCreator.CreateUninitializedObject(typeof(RT)));
      return a.Select(x =&gt; (RT)x).ToArray();        
  }  //actual implementation more complex
  
  private static T UnboxObject&lt;T&gt;(T boxedObject)
  =&gt; boxedObject;
  
  public static object CreateUninitializedObject(Type typeObject)
  =&gt; typeObject == typeof(string) ? &quot;&quot; : FormatterServices.GetUninitializedObject(typeObject);
  </code></pre>
  <p>Use of methods:</p>
  <pre><code>            var a = Model.GetType();
              var unitializedObject = CreateUninitializedObject(a);  //returns typed object
              var objectArray = CreateArrayWithNumItems(unitializedObject, 1); //returns object array
              var uob = UnboxObject(unitializedObject);  //returns typed object
              var uobObjectArray = CreateArrayWithNumItems(uob, 1);  //returns object array
              var typedArray = CreateArrayWithNumItems((dynamic) unitializedObject, 1); //returns typed object array
  </code></pre>
  <p>This seems strange to me (a.k.a I'm missing some knowledge), so I have a few questions about it.</p>
  <p>Given the same variable, why does <code>UnboxObject</code> return a typed object and <code>CreateArrayWithNumItems</code> return an array of object?</p>
  <p>Given the typed object <code>uob</code> why does <code>CreateArrayWithNumItems</code> return an array of object?</p>
  <p>Lastly (and most importantly), why does casting to dynamic prior to calling <code>CreateArrayWithNumItems</code> allow the generic method to determine the type?</p>