1

基本上我想将一个谓词传递给一个方法,该方法会产生一个字典结果,其中实体与特定 ID 相关联。但这似乎不起作用..

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

任何想法 ?

4

1 回答 1

3

return 语句应该返回Dictionary<int,Room>,而不是Dictionary<Room,int>。您还需要选择该值,否则您会得到Dictionary<int,KeyValuePair<int,Room>>

return _rooms.Where(predicate).ToDictionary(x => x.Key, x => x.Value);
于 2013-04-26T02:36:55.160 回答