c# - Create List in Linq query -


i trying create list in select new in linq set property of object. linq query below object definitions.

public class someobject {     public list<latlng> coordinates{get;set;} }  public class latlng {     public double lat;     public double lon;      public latlng(double lat, double lon)     {       this.lat = lat;       this.lon = lon;     } }   list<latlng> coordinates = null; var query = loc in loclist             select new someobject              (                 coordinates = new latlng(loc.lat,loc.lon)                 // tried line below doesn't work.                 //coordinates =  new latlng(loc.lat,loc.lon).tolist()                                  ); 

the important line this

coordinates = new latlng(loc.lat,loc.lon) 

how can make list<latlng> coordinates property list<latlng> type?

try this

var query = loc in loclist select    new someobject {      coordinates = new list<latlng> {        new latlng(loc.lat,loc.lon)      }   } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -