Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- public static class Enumerable {
- public static System.Collections.Generic.IEnumerable<TOuter> Except<TOuter, TInner, TKey, TResult>(
- this System.Collections.Generic.IEnumerable<TOuter> outer,
- System.Collections.Generic.IEnumerable<TInner> inner,
- System.Func<TOuter, TKey> outerKeySelecter,
- System.Func<TInner, TKey> innerKeySelecter,
- System.Collections.Generic.IEqualityComparer<TKey> comparer
- ) {
- var i = inner.ToDictionary( innerKeySelecter, comparer );
- return outer.Where(
- x => !i.ContainsKey( outerKeySelecter( x ) )
- );
- }
- public static System.Collections.Generic.IDictionary<K, V> ToDictionary<K, V>(
- this System.Collections.Generic.IEnumerable<V> collection,
- System.Func<V, K> keySelector,
- System.Collections.Generic.IEqualityComparer<K> keyComparer
- ) {
- System.Collections.Generic.IDictionary<K, V> output = new System.Collections.Generic.Dictionary<K, V>( keyComparer );
- foreach ( var item in collection ) {
- output.Add( keySelector( item ), item );
- }
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement