Dictionary<int, KeyValuePair<bool, int>>
来保存数据。有时我需要增加
KeyValuePair
中的int
,但是它没有setter,所以我无法这样做。是否有一种方法可以增加它?代码示例:
Dictionary<int, KeyValuePair<bool, int>> mDictionary =
new Dictionary<int, KeyValuePair<bool, int>>();
mDictionary[trapType].Value++;
//Error: The property KeyValuePair<TKey, Tvalue>>.Value has no setter
Tuple.Create(existingValue.Key, existingValue.Value + 1)
。如果逻辑上合理,创建一个类会更好,以避免不必要的new()
。 - SimpleVarbool
和int
的实际含义的单独类型。 (我也看到您已经为此编辑了您的评论 :)) - Jon Skeet