title: Order by anonymous method
body: <p>With respect to <a href="https://stackoverflow.com/questions/14938738/linq-how-to-cast-while-sorting/14938786#comment20971222_14938786">How to cast while Sorting?</a>, I tried one of the answers below.</p>
  
  <pre><code>vehicleList.OrderBy(c=&gt;
  {
      Car car = c as Car;
      if (car != null)
          return car.ModelName
      else
          return "";
  }
  </code></pre>
  
  <p>But it gives compiler error:</p>
  
  <blockquote>
    <p>The type arguments for method
    'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable,
    System.Func)' cannot be inferred from the usage. Try
    specifying the type arguments explicitly.</p>
  </blockquote>
  
  <p>What is wrong in this? How to correct?</p>
  
  <p>What I try to achieve is as below:</p>
  
  <ul>
  <li>Sort by ModelName if the object is of type Car </li>
  <li>Else if object id of type Train, then by TrainName.</li>
  </ul>