From the course: Advanced C#: Thread-Safe Data with Concurrent Collections

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Use TryAdd to add an item

Use TryAdd to add an item

- [Instructor] Now that we've seen the example code and have a feeling for how it works, let's stop working with the dictionary and start using ConcurrentDictionary, now how we'll do that is comment on line 31, and then chance the name of this variable to match the old name, now what this means is that everywhere my code was using a member of the dictionary, is now attempting to use a member of ConcurrentDictionary, and you can see there's some issues in my code down here on line 74 through 77, the add method has a red squiggle, and then down here on line 94, I've got a red squiggle on robots, so lets comment on this line, but you'll notice that everywhere else that I've worked with the dictionary, it's working, so if for instance, robots.count is good, why I'm using this foreach loop, loop through the items in the dictionary, that still works, working with the key and value, it works, things like using the key…

Contents