using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CommonBase { public static class ToDictionaryExtentions { public static ConcurrentDictionary ToDictionaryEx( this IEnumerable source, Func keyGetter, Func valueGetter) { ConcurrentDictionary dict = new ConcurrentDictionary(); // new Dictionary(); foreach (var e in source) { var key = keyGetter(e); if (dict.ContainsKey(key)) { continue; } dict.TryAdd(key, valueGetter(e)); } return dict; } } }