BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / dot-net / #336同步于 2009/12/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖

怎么清空字典里面的value值呢?

CyclingCC
2009/12/1镜像同步4 回复
Dictionary<key,value>,想把一次迭代后存的value值给清成零(value里面存的是数字),咋办捏?[em17]
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
ahomer机器人#1 · 2009/12/1
逐个删除吧 看了下,没找到 内置的清除values的方法 Dictionary<int, int> intDict = new Dictionary<int, int>(); intDict.Add(1, 1); intDict.Add(2, 2); intDict.Add(3, 3); System.Console.WriteLine("Key and values of intDict..."); foreach (KeyValuePair<int, int> keyPair in intDict) { System.Console.WriteLine("Key:{0},Value:{1}", keyPair.Key, keyPair.Value); } System.Console.WriteLine("Reset values of intDict to zero..."); foreach (KeyValuePair<int, int> keyPair in intDict) { keyPair.Value = 0; System.Console.WriteLine("Key:{0},Value:{1}", keyPair.Key, keyPair.Value); } System.Console.Read(); 【 在 CyclingCC ( CC | 刷街委员会拉P队常务副队长) 的大作中提到: 】 : Dictionary<key,value>,想把一次迭代后存的value值给清成零(value里面存的是数字),咋办捏?[em17]
qixi机器人#2 · 2009/12/1
我很好奇为什么要清0而不把所有的都清掉…… 到时候再加一遍不行么? 【 在 ahomer (水上蓝心) 的大作中提到: 】 : 逐个删除吧 : 看了下,没找到 内置的清除values的方法 : Dictionary<int, int> intDict = new Dictionary<int, int>(); : ...................
AFX机器人#3 · 2009/12/1
【 在 CyclingCC 的大作中提到: 】 : Dictionary<key,value>,想把一次迭代后存的value值给清成零(value里面存的是数字),咋办捏?[em17] 清空?我怀疑楼主其实是想要Nullable一类的东东 路过~
Nonsense机器人#4 · 2009/12/1
【 在 CyclingCC 的大作中提到: 】 : Dictionary<key,value>,想把一次迭代后存的value值给清成零(value里面存的是数字),咋办捏?[em17] var dict = new Dictionary<Guid, int>(); dict.Add(Guid.NewGuid(),100); dict.Add(Guid.NewGuid(), 101); var keys = dict.Keys.ToArray<Guid>(); foreach (var key in keys) { dict[key] = 0; }