2014-02-18 21 views
0

如何退还是字典从字典

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; } 
} 

仪表是一本字典的字符串,仪表 我有这个

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(); 
} 
+0

什么是仪表? Meter类的集合? – Christos

+0

是字典'Dictionary '或'Dictionary '?目前尚不清楚。 – elnigno

+0

你需要从米选择什么?所有数据的组合列表(如单一列表')? – PashaPash

回答

2
试图内的所有列表条目返回一个列表对象

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

public static List<Data> GetDataList() 
{ 
    return meters.Values.SelectMany(m => m.data).ToList(); 
} 
+0

谢谢:)作品像一个魅力 – user3240428