You can just iterate over the values in dic2:
Dictionary<double, double> dic1;
Dictionary<double, double> dic2;
foreach (var pair in dic2)
{
dic1[pair.Key] = pair.Value;
}
Or, if you want to update but not insert, check if the keys exist:
foreach (var pair in dic2)
{
if (dic1.ContainsKey(pair.Key))
{
dic1[pair.Key] = pair.Value;
}
}
Edit: If you really want to use Linq, you probably want to create a new dictionary rather than update an existing one:
dic1 =
(from pair in dic1
let Value = dic2.ContainsKey(pair.Key) ? dic2[pair.Key] : pair.Value
select new { pair.Key, Value }
).ToDictionary(pair => pair.Key, pair => pair.Value);
or
dic1 =
(from pair in dic1
join pair2 in dic2 on pair.Key equals pair2.Key into g
select new { pair.Key, g.DefaultIfEmpty(pair).First().Value }
).ToDictionary(pair => pair.Key, pair => pair.Value);
In my opinion that just makes it harder to read, though.