我有一个像这样的 ConcurrentDictionary:
ConcurrentDictionary<int, Dto> concurrentDictionary = new ConcurrentDictionary<int, Dto>();
Run Code Online (Sandbox Code Playgroud)
这是一个可读可写的字典,可以被多个线程使用。我可以以线程安全的方式管理可写端。当我需要访问字典中的 Dto 时,我总是使用 Linq select 方法从中获取 Dto。
IEnumerable<Dto> dtos = concurrentDictionary.Select(p => p.Value);
Run Code Online (Sandbox Code Playgroud)
我知道,并发字典上的 Linq 方法对于可读和可写的并发字典来说是无锁和线程安全的。在我使用 Linq 访问 Dto 之后,在这些 Dto 上使用一些读取函数是否是线程安全的?我的意思是在 foreach 循环中访问这些 Dto 或从中创建新列表并对这些 Dto 的属性进行过滤或排序?
ConcurrentDictionary<int, Dto> concurrentDictionary = new ConcurrentDictionary<int, Dto>();
for (int i = 0; i < 10000; i++)
{
concurrentDictionary.TryAdd(i, new Dto()
{ Id = i, Name = RandomString(35), Type = "new", IsActive = true} );
}
IEnumerable<Dto> dtos = concurrentDictionary.Select(p => p.Value);
ArrayList arrayList …
Run Code Online (Sandbox Code Playgroud) 什么是Java的C#中的float.floatToRawIntBits方法实现?