在Linq查询中创建列表

时间:2015-07-21 21:24:54

标签: c# linq

我正在尝试在fileExec的{​​{1}}中创建List来设置对象的属性。 linq查询位于对象定义之下。

select new

重要的是这个

Linq

如何将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 = from loc in locList select new SomeObject ( coordinates = new LatLng(loc.Lat,loc.Lon) // I tried the line below but it doesn't work. //coordinates = new LatLng(loc.Lat,loc.Lon).ToList() ); 作为coordinates = new LatLng(loc.Lat,loc.Lon) 类型的List<LatLng>属性进入coordinates

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

var query = from loc in locList select 
  new SomeObject { 
    coordinates = new List<LatLng> { 
      new LatLng(loc.Lat,loc.Lon) 
    }
  }