Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 从字典返回列表对象_C#_Linq_Dictionary_Collections - Fatal编程技术网

C# 从字典返回列表对象

C# 从字典返回列表对象,c#,linq,dictionary,collections,C#,Linq,Dictionary,Collections,如何返回字典中的所有列表条目 public class Meter { public string MeterID { get; set; } public List<Data> data { get; set; } } public class Data { public string Time { get; set; } public int Signal { get; set; } } 公共类仪表 { 公共字符串MeterID{get;set

如何返回字典中的所有列表条目

public class Meter
{
    public string MeterID { get; set; }
    public List<Data> data { get; set; }
}

public class Data
{
    public string Time { get; set; }
    public int Signal { get; set; }
}
公共类仪表
{
公共字符串MeterID{get;set;}
公共列表数据{get;set;}
}
公共类数据
{
公共字符串时间{get;set;}
公共int信号{get;set;}
}
米是一个字典字符串,米 我试过这个

private static Dictionary<string, Meter> meters = new Dictionary<string, Meter>();
public static List<Meter> GetDataList()
{
    return meters.Where(g => g.Key.Equals(Data)).Select(g => g.Value).ToList();
}
private static Dictionary meters=new Dictionary();
公共静态列表GetDataList()
{
返回meters.Where(g=>g.Key.Equals(Data)).Select(g=>g.Value.ToList();
}

选择所有仪表的单一数据列表:

public static List<Data> GetDataList()
{
    return meters.Values.SelectMany(m => m.data).ToList();
}
公共静态列表GetDataList()
{
返回meters.Values.SelectMany(m=>m.data.ToList();
}

什么是仪表?仪表类的集合?是字典
字典
还是
字典
?不清楚。你到底需要从仪表中选择什么?所有数据的组合列表(作为单个
列表
)?仪表是仪表和字典的集合,最好是单个列表谢谢:)工作起来很有魅力