我将csv导入对象
obj_cellelist = (from line in File.ReadAllLines(pathCelle)
let columns = line.Split(stringSeparators, StringSplitOptions.None)
select new obj_celle()
{
Cgi = columns[0],
zonaNis = columns[0].Length > 8 ? int.Parse(columns[0].Substring(5, 3)) : -1,
codice_Sarf = columns[0].Length > 11 ? int.Parse(columns[0].Substring(8, 4)) : -1,
IDCella = columns[1],
Operatore = columns[2],
Void = columns[3],
Via = columns[4].Replace("''", "'"),
Comune = columns[5].Replace("�", "A'"),
Provincia = columns[6],
Regione = provincie.Keys.Contains(columns[6]) ? provincie[columns[6]] : "",
Nazione = columns[7],
Latitudine = decimal.Parse(columns[8].Replace('.', ',')) ,
Longitudine = decimal.Parse(columns[9].Replace('.', ',')) ,
Void1 = columns[10],
Azimuth = columns[11].Length > 0 ? int.Parse(columns[11]) : -1 }).ToList();
我需要通过Longitudine和Latitudine分组并获得所有不同的Azimuth。每个Latitudine,Longitudine最多有三个不同的方位角。 其他值是相同的,除了cgi,我不需要。 新对象应该包含 zonaNis,codice_Sarf,IDCella,算符,空隙,VIA,拱廊,省报,大区,Nazione,Latitudine,Longitudine,Void1,Azimuth1,Azimuth2,Azimuth3
示例:
861 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 110
862 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 240
864 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 110
865 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 240
867 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 110
868 ### 3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 240
对象输出应
3OF034AA ### VODAFONE ###### STRADA TEST ### NOLA ### AR ### ITALY ### 43.74619685 ### 11.71866206 ###### 110 ### 240
答案 0 :(得分:0)
obj_cellelist
.GroupBy(p => new { Lat = p.Latitudine, Long = p.Longitudine })
.Select(g => new { place = g.Key, azimuths = g.Select(a => a.Azimuth).Disctinct() })
.ToList();
这将为您提供具有两个属性的对象列表。第一个属性是obj_celle类型,另一个属性是不同方位角列表。