dictionary的用法://初始化添加所有车位进这队列 Utility.Effectlist.Add("Carlot", 0); //每触发一次,用这个增加数量 Utility.Effectlist["Carlot"]++; //遍历显示 foreach (var item in Utility.Effectlist) { Console.WriteLine("key:{0} value:{1}", item.Key, item.Value); }
实际应用
private void button8_Click(object sender, EventArgs e) { Dictionary<string, int> templist = new Dictionary<string, int>(); foreach (var item in Utility.Effectlist) { templist.Add(item.Key, 0); // Utility.Effectlist[item.Key] = 0; // dgvCountShow.DataSource = Utility.Effectlist.ToArray(); } Utility.Effectlist.Clear(); Utility.Effectlist = templist; dgvCountShow.DataSource = Utility.Effectlist.ToArray();//绑定到dgv }
时间: 2024-10-08 10:28:03