簡體   English   中英

如何從C#中的嵌套並發字典獲取值到列表中

[英]How to get values into list from nested concurrent dictionary in c#

我有一個嵌套的並發字典,如下所示:

ConcurrentDictionary<string,ConcurrentDictionary<string,<Class Object>>>

我想將所有對象(內部字典的值)放入列表中以進行進一步處理,而無需知道任何鍵。

我嘗試了以下兩種解決方案,但不適用於我,

  1. 外部dictionary.Values.Select(x=> x.Values)
  2. foreach循環

第一個解決方案的問題是它不會只提供對象,第二個解決方案很耗時。

如果運行dictionary.Values.Select(x=> x.Values) ,則不會從內部字典中獲得對象值的列表; 您將獲得對象值列表的列表

要“拉平”該列表,請使用SelectMany

foreach (var inner  in dictionary.Values.SelectMany(x=> x.Values)) {
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM