title: Anonymously typed List or List of Objects
body: <p>I have the following problem (simplified).</p>
  
  <p>I have a list of dogs:</p>
  
  <pre><code>public List&lt;Dog&gt; dogs { get; set; }
  </code></pre>
  
  <p>I currently access this list as a json object by converting it in a view:</p>
  
  <pre><code>@(new HtmlString(@Json.Encode(@ViewBag.dogs)))
  </code></pre>
  
  <p>I then iterate through this json object using javascript and display it on a page.</p>
  
  <p>I would like to add cars to this list. </p>
  
  <p>However, since the list is strongly typed as a list of <code>dogs</code> my first thought was to create the list as the one thing <code>dogs</code> and <code>cars</code> have in common, <strong>they're both objects</strong>.</p>
  
  <p>When I tried to change my list of dogs into a list of <code>objects</code>, I received the following error</p>
  
  <pre><code>Cannot implicitly convert type 'System.Collections.Generic.List&lt;object&gt;' to System.Collections.Generic.List&lt;dog&gt;
  </code></pre>
  
  <p>I researched that and found <a href="https://stackoverflow.com/q/6557/1324019">this</a> question which didn't help me much except to tell me that I would not be able to have a list of dogs and cars. For my purposes, however, this isn't suitable. I need my list to contain both dogs and cars, so that I have access to both of them in my application.</p>
  
  <p>One solution I anticipate being suggested is that I have two separate lists, and make two separate ajax requests. However, I need to mix cars and dogs in a specific order (based on the time they were created essentially) so that solution isn't ideal.</p>
  
  <p>In short, I'm wondering what the best way to accomplish this is. Perhaps I've gone off in completely the wrong direction, so I'm not opposed to doing something completely different if it makes sense.</p>
  
  <p>Thanks for the help as always!</p>
  
  <p>EDIT: I've tried the cast and that works. However, I need to access a property of dog (let's call it "fur") and I don't seem to be able to do that (do I need to cast again?)</p>
  
  <pre><code>'object' does not contain a definition for 'fur'
  </code></pre>