Unfortunately .ForEach()
is only defined on the List<>
class.
You could either use .ToList()
first to get access to .ForEach
but that will, of course, lower the performance compared to just using foreach
or you could create extension-methods for that:
public static void ForEach<T, U>(this Dictionary<T, U> d, Action<KeyValuePair<T, U>> a)
{
foreach (KeyValuePair<T, U> p in d) { a(p); }
}
public static void ForEach<T, U>(this Dictionary<T, U>.KeyCollection k, Action<T> a)
{
foreach (T t in k) { a(t); }
}
public static void ForEach<T, U>(this Dictionary<T, U>.ValueCollection v, Action<U> a)
{
foreach (U u in v) { a(u); }
}
If you are interested in further information, there is already a similar article on SO.