Returns TRUE if the item does NOT exist in the dictionary. This performs MUCH faster than ContainsKey() or ContainsValue() - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

Returns TRUE if the item does NOT exist in the dictionary. This performs MUCH faster than ContainsKey() or ContainsValue()

Demo Code


using System.Linq;
using System.Collections.Generic;

public class Main{
        /// <summary>
        /// Returns TRUE if the item does NOT exist in the dictionary. This performs MUCH faster than ContainsKey() or ContainsValue()
        /// </summary>
        public static bool DoesNotContain<TKey, TValue>(this IDictionary<TKey, TValue> items, TKey key)
        {//from  ww w  .  ja  v  a  2  s . c  o m
            return Contains(items, key) == false;
        }
        public static bool DoesNotContain<T>(this IEnumerable<T> items, T item)
        {
            return System.Linq.Enumerable.Contains(items, item) == false;
        }
        /// <summary>
        /// Returns TRUE if the item exists in the dictionary. This can perform MUCH faster than ContainsKey() or ContainsValue()
        /// </summary>
        public static bool Contains<TKey, TValue>(this IDictionary<TKey, TValue> items, TKey key)
        {
            TValue dummy;
            return items.TryGetValue(key, out dummy);
        }
}

Related Tutorials