Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取列表的元素_C#_Asp.net Mvc_List_C# 4.0_Arraylist - Fatal编程技术网

C# 获取列表的元素

C# 获取列表的元素,c#,asp.net-mvc,list,c#-4.0,arraylist,C#,Asp.net Mvc,List,C# 4.0,Arraylist,我在下面写了代码,我想得到lat和lng值,但我不知道怎么做。我想学习获取列表中的元素 public class GeoCode { public List<Results> Results { get; set; } } public class Results { public Geometry geometry { get; set; } public class Geometry { public LL loc

我在下面写了代码,我想得到lat和lng值,但我不知道怎么做。我想学习获取列表中的元素

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; }
    }
}
它将返回具有两个属性lat和lng的LL列表。如果要获取索引2处元素的lat和lng,请尝试以下操作:

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

注意:您应该使用大写的第一个字母命名属性,例如,Lat not Lat。

您需要展开您的问题。是否要通过特定属性从列表中获取元素?结果[0]返回第一个元素,foreachvar res在结果循环中遍历所有元素,您想获取什么?我想获取结果列表中的元素lat和lng查看,res.geometry.location.lat
double lat = yourList[2].lat;
double lng = yourList[2].lng;