1
ConcurrentDictionary<int, int> dic = new ConcurrentDictionary<int, int>();
dic.AddOrUpdate(1, 2, (s, i) => 0);
dic.AddOrUpdate(2, 3, (s, i) => 0);
dic.AddOrUpdate(3, 1, (s, i) => 0);
dic.AddOrUpdate(4, 7, (s, i) => 0);

値が 5 より大きいキーのみを選択したいのですが、どうすればよいですか?

4

1 に答える 1

5

エントリを選択し、値に基づいてフィルタリングしてから、キーに射影するだけです。

var keys = dic.Where(entry => entry.Value > 5)
              .Select(entry => entry.Key);

このアプローチは、どのような場合でも問題ないことに注意してIDictionary<,>くださいConcurrentDictionary<,>

于 2015-01-29T18:46:27.603 に答える