سؤال

When you are using ConcurrentDictionary and trying to add new key pairs to it using TryAdd it checks whether value exists and then add if not. Is there any way I can add duplicate keys wit different vales? Or maybe there is alternative thread-safe dictionary which allows to do that?

هل كانت مفيدة؟

المحلول

A ConcurrentDictionary<TKey, TValue> cannot contain duplicate keys.

I would go with a ConcurrentBag<KeyValuePair<string, string>> if ordering wasn't an issue or you might use a ConcurrenyDictionary <string, List<string>> and filter out the proper value as needed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top