-2

I have a concurrent dictionary and would like to update an object property (e.g. an employee age) by another method:

For example (pseudo code)

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
}

My idea is to foreach loop over the key/value pair and search John then update his age.

foreach (var key in records.Keys) {
    //search "John" and update his age
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Ben
  • 17
  • 2
  • 2
    Couple of things: 1. It helps if it's clearer what is being asked. From reading your post, I'm thinking your "problem" or main question is that you are wondering if there is a better way to update the age than having to loop over all keys to find John. Is that right? 2. It's unclear whether you are just trying to update one record or all the records. I think it's just one record, is that right? 3. You'd be more likely to get a response with real code, not pseudo-code. At SO the question generally is expected to be based on work already done, which is why real code is important. – DWright May 10 '15 at 01:40

1 Answers1

0

You don't have to loop over the keys if you already know it's john:

idict["john"].age = 32;
Stefan
  • 121
  • 7