我有一个并发字典,并希望通过其他方法更新对象属性(例如员工年龄):
例如(伪代码)
class Employee
{
string name;
int age;
}
main()
{
//Sample dic => iDictionary("John", Employee)
UpdateAge(idictionary)
print (idictionary["john"]) // I would like to see the updated value of Employee.age of John here.
}
UpdateAge(iDictionary<string, Employee> idict) {
//update age of John here
}
我的想法是foreach
循环键/值对并搜索John
然后更新他的年龄。
foreach (var key in records.Keys) {
//search "John" and update his age
}
答案 0 :(得分:0)
如果你已经知道了关键,你就不必循环关键:
idict["john"].age = 32;