获取列表元素

编程入门 行业动态 更新时间:2024-10-23 08:29:31
本文介绍了获取列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在下面编写了代码,我想获得 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 个属性 latlng.如果您想获取索引 2 处元素的 latlng,请尝试以下操作:

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-16 10:04:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/884947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!