本文介绍了获取列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送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 个属性 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屋!
更多推荐
[db:关键词]
发布评论