C# List中筛选出元素中 某些属性相同的元素数据

首先有一个List GetPlayBackList
GetPlayBackList中的元素属性有_Time、_PointsItem、_Points、_PeopleCount
GetPlayBackList中的元素是按照以上属性循环保存的比如:
{
“_Time”: “2019-09-19 11:31:06”,
“_PointsItem”: {
“_Points”: [
{
“x”: -184.2381134033203,
“y”: 5.010000705718994,
“z”: -2.090165615081787
},
{
“x”: -155.53150939941407,
“y”: 5.010000705718994,
“z”: -2.0713794231414797
}
],
“_PeopleCount”: 30
},
“_HeatPoints”: []
},
{
“_Time”: “2019-09-19 11:31:08”,
“_PointsItem”: {
“_Points”: [
{
“x”: -97.76271057128906,
“y”: 5.0099992752075199,
“z”: 8.555625915527344
},
{
“x”: -81.80867004394531,
“y”: 5.010000228881836,
“z”: 0.8152670860290527
}
],
“_PeopleCount”: 30
},
“_HeatPoints”: []
}
现在需要在GetPlayBackList中筛选出_Points相同的元素总共有几个,可以使用Linq的GroupBy先进行分组

  public string Getcontent(DataItem data)
    {
        string result = "";

        foreach (var item in data._PointsItem._Points)
        {
            result = result + item.ToString();
        }
        return result;
    }
var _Group = GetPlayBackList.GroupBy(g => Getcontent(g)).ToList();

这样就可以筛选出来了。

你可能感兴趣的:(C#)