title: Covariance in generic collections C#
body: <p>I have a some classes and interface</p>
  
  <pre><code>public interface IGeoObject
      {
          GeoCoordinate GetGeocoordinate();
      }
  
  public class User : IGeoObject
      {
          public GeoCoordinate GetGeocoordinate()
          {
              //...
              return GeoCoordinate;           
          }
      }  
  
  public class Venue : IGeoObject
      {    
          public GeoCoordinate GetGeocoordinate()
          {
              //...
              return GeoCoordinate;
          }
      }
  
  public class Place : IGeoObject
      {    
          public GeoCoordinate GetGeocoordinate()
          {
              //...
              return GeoCoordinate;
          }
      }
  </code></pre>
  
  <p>I have, example variable users with type <code>List&lt;User&gt;</code></p>
  
  <p>And I have method with signature </p>
  
  <pre><code>double GetMinDistance(List&lt;IGeoObject&gt; objects, GeoCoordinate position)
  </code></pre>
  
  <p>I can't pass users to <code>GetMinDistance</code>, because covariance of generic types not work.</p>
  
  <p>I can create additional list and use method <code>.ConvertAll</code> (or <code>.CasT&lt;T&gt;</code>):</p>
  
  <pre><code>List&lt;IGeoObject&gt; list = new List&lt;User&gt;(listUser).ConvertAll(x =&gt; (IGeoObject)x);
  var dist = GeoTest.GetMinDistance(list, position);
  </code></pre>
  
  <p>I'm not sure that this is the most elegant solution. Most embarrassing that the <strong>caller must do this conversion</strong>.</p>
  
  <p>This is similar to my problems in the architecture? There are more elegant solutions?</p>
  
  <p>P.S. Long story, but I really can not give the coordinates of the same species in all classes.</p>