简体   繁体   English

是否有Java#当前的Java ConcurrentHashMap

[英]Is there a c# equivalent of Java ConcurrentHashMap

I need a dictionary/hashmap in c# that allow you to do the following 我需要c#中的字典/ hashmap,允许您执行以下操作

  1. put values and iterate at the same time without a lock 放置值并在没有锁定的情况下同时迭代
  2. lock only put. 锁只放。 get are not locked and you may get many times concurrently get没有锁定,你可能会同时多次访问

Thanks 谢谢

check out the System.Collections.Concurrent - Namespace! 看看System.Collections.Concurrent - 命名空间! http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx

对于我来说,这听起来像ConcurrentDictionary<TKey, TValue> ,如果您安装了Reactive Extensions ,则可以在.NET 4.0 .NET 3.5中使用。

Have a look at the ConcurrentDictionary here: http://msdn.microsoft.com/en-us/library/dd287191.aspx . 在这里查看ConcurrentDictionary: http//msdn.microsoft.com/en-us/library/dd287191.aspx This should do what you're looking for. 这应该做你想要的。 Keep in mind, it's .Net 4 only. 请记住,它只是.Net 4。

You could also write your own class by using the ReaderWriterLockSlim Class . 您也可以使用ReaderWriterLockSlim Class编写自己的ReaderWriterLockSlim Class

Otherwise simply take a look into the System.Collections.Concurrent Namespace . 否则,只需查看System.Collections.Concurrent Namespace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM