C#中List<T>排序

首先,List中T的定义如下:

    /// <summary>
    /// GeoJSON格式的参数
    /// </summary>
    public class BodyParamShapeDistance
    {
        /// <summary>
        /// 几何对象
        /// </summary>
        [Newtonsoft.Json.JsonProperty("Shape")]
        public GeoJSON.Net.Geometry.IGeometryObject Shape { get; set; }

        /// <summary>
        /// 距离
        /// </summary>
        [Newtonsoft.Json.JsonProperty("Distance")]
        public double Distance { get; set; }
    }
我们定义一个List<T>:

                    List<BodyParamShapeDistance> lsResult = new List<BodyParamShapeDistance>() { };
并对进进行赋值(代码省略)。

然后,按照其Distance进行排序:

lsResult.OrderBy((e1) => { return System.Convert.ToDouble(e1.Distance); }).ToList()
结果如下:

[
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733091.6109,
                5126223.190200001
            ]
        },
        "Distance": 0.6398240774310442
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733110.031999998,
                5126207.581500001
            ]
        },
        "Distance": 24.49381893718201
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733116.322999999,
                5126215.005900003
            ]
        },
        "Distance": 26.55484821473176
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733116.5524,
                5126215.2766999975
            ]
        },
        "Distance": 26.69409126958543
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733117.426799998,
                5126216.308700003
            ]
        },
        "Distance": 27.260763998304128
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733111.483900003,
                5126241.340800002
            ]
        },
        "Distance": 27.495001437711842
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733089.886,
                5126250.759099998
            ]
        },
        "Distance": 27.78144396311649
    },
    {
        "Shape": {
            "type": "Point",
            "coordinates": [
                13733118.289399996,
                5126217.326700002
            ]
        },
        "Distance": 27.872884404584443
    }
]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值