获取列表元素 [英] Getting element of list

查看:55
本文介绍了获取列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了belown的代码,我想获取lat和lng值,但是我不知道该怎么做.我想学习在列表中获取元素.

I wrote code belown and I want to get lat and lng values but i dont know how to do it. I want to learn getting element in the list.

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; }
    }
}

推荐答案

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

它将返回 LL 的列表,该列表具有2个属性 lat lng .如果要在索引2处获取元素的 lat lng ,请尝试以下操作:

It will return a list of LL which has 2 properties lat and lng. If you want to get the lat and lng of the element at index 2, try this:

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

注意::您应使用首字母大写来命名属性,例如, Lat 而不是 lat .

NOTE: You should name the Properties with the first letter capitalized, for example, Lat not lat.

这篇关于获取列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆