C# 更新ConcurrentDictionary中的值<;字符串、元组<;字符串,字符串>&燃气轮机;

C# 更新ConcurrentDictionary中的值<;字符串、元组<;字符串,字符串>&燃气轮机;,c#,linq,dictionary,tuples,C#,Linq,Dictionary,Tuples,基于ConcurrentDictionary,我需要更新Tuple.item1字符串以删除空格 到目前为止,我所尝试的: ConcurrentDictionary<string, Tuple<string, string>> myDictionary = new <string, Tuple<string, string>> RemoveSpacesFromDic(myDictionary); public Boolean ShouldRemov

基于
ConcurrentDictionary
,我需要更新Tuple.item1字符串以删除空格

到目前为止,我所尝试的:

ConcurrentDictionary<string, Tuple<string, string>> myDictionary = new <string, Tuple<string, string>>
RemoveSpacesFromDic(myDictionary);

public Boolean ShouldRemoveSpace(string myValue)
{
   return myValue.Contains(" ");
}

public void RemoveSpacesFromDic(ConcurrentDictionary<string, Tuple<string, string>> sampleDictionary)
{
   List<string> keys = new List<string>(sampleDictionary.Keys);
   foreach (string key in keys)
   {
      if (ShouldRemoveSpace(sampleDictionary[key].Item1))
      {
         string newValue= sampleDictionary[key].Item1;
         //Remove spaces from newValue logic
         sampleDictionary[key] = new Tuple<string, string>(newValue, sampleDictionary[key].Item2);
      }
    }
}
ConcurrentDictionary myDictionary=新建
RemoveSpacesFromDic(myDictionary);
公共布尔值ShouldRemoveSpace(字符串myValue)
{
返回myValue.Contains(“”);
}
public void RemoveSpacesFromDic(ConcurrentDictionary示例字典)
{
列表键=新列表(sampleDictionary.keys);
foreach(字符串键入键)
{
if(ShouldRemoveSpace(sampleDictionary[key].Item1))
{
字符串newValue=sampleDictionary[key].Item1;
//从newValue逻辑中删除空格
sampleDictionary[key]=新元组(newValue,sampleDictionary[key].Item2);
}
}
}

有没有一种优雅的方法可以在没有键逻辑列表的情况下做到这一点?可能使用LINQ。

以下是使用LINQ的方法:

yourDic.ToDictionary(x => x.Key,                    
                     x => Tuple.Create(x.Value.Item1.Replace(" ", ""), x.Value.Item2));

示例输入和预期输出将非常有用。我已将类型更改为
ConcurrentDictionary
works。。。只需注意>>您可以替换而不更新元组。。。