title: C# Cast Object to List of Base Class
body: <p>I have the following class structure:</p>
  
  <pre><code>public class Fruit { }
  public class Apple : Fruit { }
  </code></pre>
  
  <p>And then I am using a method from the .net framework that gets me a property value from a class returned as an object.  So, </p>
  
  <pre><code>// values will be of type List&lt;Apple&gt;
  object values = someObject.GetValue()
  </code></pre>
  
  <p>I now have this values object of type List and I want to cast it to a List of type Fruit.  I tried the following but it didn't work.</p>
  
  <pre><code>List&lt;Fruit&gt; fruits = values as List&lt;Fruit&gt;;
  </code></pre>
  
  <p>Anyone know how to go about casting an object to a List of its base class?</p>
  
  <p>Update:  At the point of casting I don't know that the values object is of type List  I just know that it should be a List of a type that inherits from Fruit.</p>