2013-04-26 23 views
1

基本上我想傳遞一個謂詞到一個方法,這個方法會導致一個與實體關聯到一個特定的Id的字典結果。但這似乎不起作用..想傳遞一個謂詞到一個方法來得到一個字典結果

public Dictionary<int, Room> GetRooms(Func<KeyValuePair<int, Room>, bool> predicate) 
{ 
     return _rooms.Where(predicate).ToDictionary<Room, int>(x => x.Key); 
} 

任何想法?

回答

3

return語句應返回Dictionary<int,Room>而不是Dictionary<Room,int>。您還需要選擇值,否則您將得到一個Dictionary<int,KeyValuePair<int,Room>>

return _rooms.Where(predicate).ToDictionary(x => x.Key, x => x.Value); 
相關問題