using System.Collections.Generic;
public static Dictionary<TKey, KeyValuePair<TValue1, TValue2>> Merge<TKey, TValue1, TValue2>(Dictionary<TKey, TValue1> d1, Dictionary<TKey, TValue2> d2) where TKey : notnull {
join d2kv in d2 on d1kv.Key equals d2kv.Key
select KeyValuePair.Create(d1kv.Key, KeyValuePair.Create(d1kv.Value, d2kv.Value))
public static Dictionary<TKey, KeyValuePair<TValue1, TValue2>> MergeLeft<TKey, TValue1, TValue2>(Dictionary<TKey, TValue1> d1, Dictionary<TKey, TValue2> d2) where TKey : notnull {
(d1kv, g) => g.DefaultIfEmpty().Select(
d2kv_def => KeyValuePair.Create(d1kv.Key, KeyValuePair.Create(d1kv.Value, d2kv_def.Value))
public static void Main()
var a = new Dictionary<int, string>() { [1] = "abc", [2] = "def", [0] = "zzz" };
var b = new Dictionary<int, string>() { [1] = "ABC", [2] = "DEF", [1000] = "ZZZ" };
var result = MergeLeft(a, b);
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(result));