2014-02-18 19 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