哈希表的遍历 问题 如何遍历一个哈希表? 不能遍历整个对象,而 Keys: 获取哈希表中键的集合 是遍历Values Values:获取哈希表中值的集合 foreach (Object stuo in students.Values) Key Value { Student stu =(Student)stuo; Key Value Console.WriteLine(stu.Name); Key Value foreach(string name in students.Keys) Key Value 可以遍历Keys Console.WriteLine(name), Key Value foreach(DictionaryEntry dicEntry in students) Values I键dicEntry.Key (Student )dicEntry.Value 6
6 哈希表的遍历 foreach (Object stuo in students.Values) { Student stu = (Student)stuo; Console.WriteLine(stu.Name); } 如何遍历一个哈希表? Key Value Key Value Key Value Key Value Key Value Values foreach (string name in students.Keys) { Console.WriteLine(name); } 可以遍历Keys Keys: 获取哈希表中键的集合 Values: 获取哈希表中值的集合 不能遍历整个对象,而 是遍历Values foreach (DictionaryEntry dicEntry in students) //键 dicEntry .Key //值 (Student )dicEntry.Value
哈希表中元素的查找 Contains方法 Key:要在哈希表中定位的键 bool Contains object key); 返回值:true,false ContainsValue方法 Value:在哈希表中定位的值 bool ContainsValue object value 返回值:true,false
7 哈希表中元素的查找 bool Contains ( object key); Key:要在哈希表中定位的键 bool ContainsValue ( object value); ▪ Contains方法 ▪ ContainsValue方法 返回值:true,false Value:在哈希表中定位的值 返回值:true,false