Well I was adding things to a dictionary today (Because im lazy, I have to store 2 values, and I really cant be bothered with creating a class just for that), and I wanted to run a ForEach(System.Action<T>) on it, because I like doing that on System.Collections.Generic.List<t> – it works well, so why change what you know?

But, it turns out Dictionary<TKey, TValue> dosent have a .ForEach. It implements IEnumerable, but it dosent have support for the .ForEach, which is rather strange, since they both do the same thing, but it dosent have the Action<T> method. So I did some digging, and found that .ForEach is a method that belongs to List<T>, and its pretty much the only way to do it (There is a System.Array.Foreach(T[] array, Action<T>) method, but that dosent work with a dictionary.

What I see happening is me extending Dictionary<TKey, TValue> to add a .ForEach (And the other functions that are missing from it, in my opinion at least), because I think that since it implements IEnumerable<T>, it should support .ForEach.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DotNetKicks
  • DZone