私はConcurrentDictionaryの値としてIListを持っています。リスト内の値を更新するためにConcurrentDictionaryのリストを更新する
ConcurrentDictionary<int, IList<string>> list1 = new ConcurrentDictionary<int, IList<string>>;
私はこれを行う:
しかしif (list1.ContainsKey[key])
{
IList<string> templist;
list1.TryGetValue(key, out templist);
templist.Add("helloworld");
}
、templist更新ConcurrentDictionaryに文字列を追加していますか?もしそうなら、データ破損が起こらないように、スレッドセーフな更新ですか?
または私はリストの代わりにConcurrentBagを使用した場合ConcurrentDictionary
EDIT
内部リストを更新または作成するためのより良い方法があるが、どのように私はこれを実装するのでしょうか?具体的には、どうすれば更新できますか? ConcurrentDictionaryのTryUpdateメソッドは少し過度に感じます。
ConcurrentBag.Addは、スレッドセーフなマンナでConcurrentDictionaryを更新しますか?
ConcurrentDictionary<int, ConcurrentBag<string>> list1 = new ConcurrentDictionary<int, ConcurrentBag<string>>
私はdownvoterを質問します:私の答えをdownvoteしないでください?今はそれが私のように見えます。 – CodeCaster
私はそれがあなただったと一瞬は考えなかった。私はあなたが常に下降音を説明することを知っている! :) –