Mar*_*sen 73 .net c# concurrency
如果字典不包含给定键的值,它是否只返回false,或者由于线程竞争条件它也会返回false,就像另一个线程添加/更新某些东西一样?
代码问题:
ConcurrentDictionary<int, string> cd = new ConcurrentDictionary<int, string>();
// This might fail if another thread is adding with key value of 1.
cd.TryAdd(1, "one");
// Will this ever fail if no other thread ever removes with the key value of 1?
cd.TryRemove(1);
Run Code Online (Sandbox Code Playgroud)
编辑: 我认为它只会返回false,如果它不包含给定键的值,但想要绝对确定.
| 归档时间: |
|
| 查看次数: |
14666 次 |
| 最近记录: |