Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何计算父项';具有linq的s性质_C#_Linq_Wpfdatagrid - Fatal编程技术网

C# 如何计算父项';具有linq的s性质

C# 如何计算父项';具有linq的s性质,c#,linq,wpfdatagrid,C#,Linq,Wpfdatagrid,我有两个像这样的对象集合 public class Meter { public string UID { get; set; } public string NR { get; set; } public List<GMSData> data { get; set; } } public class GSMData : Meter { public DateTime TimeStamp { g

我有两个像这样的对象集合

public class Meter
    {
        public string UID { get; set; }
        public string NR { get; set; }
        public List<GMSData> data { get; set; }
    }

public class GSMData : Meter
    {
        public DateTime TimeStamp { get; set; }
        public int CellID { get; set; }
    }

 public static List<Meter> GetMeterUIDList()
        {
            return meters.Values.ToList();
        }
        public static List<GSMData> GetGsmdataList()
        {
            return meters.Values.SelectMany(m => m.Gsmdata)
                .OrderBy(t => t.TimeStamp)
                .ToList();
        }
公共类仪表
{
公共字符串UID{get;set;}
公共字符串NR{get;set;}
公共列表数据{get;set;}
}
公共类GSMData:仪表
{
公共日期时间时间戳{get;set;}
public int CellID{get;set;}
}
公共静态列表GetMeterUIDList()
{
返回meters.Values.ToList();
}
公共静态列表GetGsmdataList()
{
返回meters.Values.SelectMany(m=>m.Gsmdata)
.OrderBy(t=>t.TimeStamp)
.ToList();
}
我需要得到每个CellId的所有NR,并计算每个CellId上有多少NR。 我该怎么做呢?

也许:

var idGroups = meters
    .SelectMany(m => m.data)
    .GroupBy(d => d.CellID)
    .Select(g => new { CellID = g.Key, UniqueNr = g.Select(m => m.NR).Distinct() });

foreach (var g in idGroups)
    Console.WriteLine("CellID: {0}  Count: {1}", g.CellID, g.UniqueNr.Count());

如果
NR
不需要是唯一的,请删除
Distinct

两个集合?让他们看看。看来我们对你的问题没有一个完整的了解。你有一个列表或者你想做什么:)我希望它现在更有意义:)一个愚蠢的问题,但是你如何将它返回到列表或字典?@user3240428:什么列表或字典?公共字典GetCellIDMCount()fx。那么为什么要为计数添加一个字符串呢?你只需要将
附加到字典(x=>x.CellID,x=>x.uniquener.count())到上面的查询。