我有iDictionary并想更新键/值对的值(通过引用传递)c#

时间:2015-05-10 00:43:05

标签: c# idictionary

我有一个并发字典,并希望通过其他方法更新对象属性(例如员工年龄):

例如(伪代码)

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
}

1 个答案:

答案 0 :(得分:0)

如果你已经知道了关键,你就不必循环关键:

idict["john"].age = 32;