2013-08-19 76 views
-3

我寫了代碼belown,我想獲取經緯度值,但我不知道如何去做。我想學習獲取列表中的元素。獲取列表中的元素

public class GeoCode 
{ 
    public List<Results> Results { get; set; } 
} 
public class Results 
{   
    public Geometry geometry { get; set; } 

    public class Geometry 
    { 
     public LL location { get; set; } 
     public ViewPort viewPort { get; set; } 
    } 
    public class LL 
    { 
     public double lat { get; set; } 
     public double lng { get; set; } 
    } 
    public class ViewPort 
    { 
     public LL northeast { get; set; } 
     public LL southwest { get; set; } 
    } 
} 
+0

您需要擴展您的問題。你想從特定屬性的列表中獲取元素嗎? – DGibbs

+2

'Results [0]'返回第一個元素,'foreach(結果中的var res循環遍歷所有這些元素,你試圖獲得什麼? – Sayse

+0

我想在結果列表中獲取元素「lat」和「lng」 –

回答

3
var yourList = yourGeoCode.Results 
          .Select(x=>x.geometry.location).ToList(); 

它將返回的LL其中有2個屬性latlng列表。如果你想獲得該元素的latlng在指數2,試試這個:

double lat = yourList[2].lat; 
double lng = yourList[2].lng; 

注:您應該爲屬性的第一個字母大寫,例如,Latlat