You can write an extension method easily:
public static class LinqExtensions
{
public static void ForEach<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Action<TKey, TValue> invoke)
{
foreach(var kvp in dictionary)
invoke(kvp.Key, kvp.Value);
}
}
Using like this:
dict.ForEach((x, y) =>
{
Console.WriteLine($"(Key: {x}, value: {y})");
});
Produces
Key: K1, value: V1
Key: K2, value: V2
Key: K3, value: V3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…