Exemplo n.º 1
0
        /// <summary>
        /// Intersect two lists
        /// </summary>
        /// <param name="list1">First dictionary of instances to intersect</param>
        /// <param name="list2">Second dictionary of instances to intersect</param>
        public static ONListDictionary <TKey, TValue> Intersection(ONListDictionary <TKey, TValue> list1, ONListDictionary <TKey, TValue> list2)
        {
            ONListDictionary <TKey, TValue> lList = new ONListDictionary <TKey, TValue>();

            if ((list1 == null) || (list2 == null))
            {
                return(lList);
            }

            foreach (ONListDictionaryEntry <TKey, TValue> lEntry in list1)
            {
                if (list2.ContainsKey(lEntry.Key))
                {
                    lList.Add(lEntry.Key, lEntry.Value);
                }
            }

            return(lList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Intersects the dictionary with other dictionary
        /// </summary>
        /// <param name="list">Dictionary to intersect</param>
        public void Intersection(ONListDictionary <TKey, TValue> list)
        {
            if (list == null)
            {
                Clear();
                return;
            }

            int mMaxIndex = -1;

            foreach (ONListDictionaryEntry <TKey, TValue> lEntry in this)
            {
                if (!list.ContainsKey(lEntry.Key))
                {
                    Remove(lEntry.Key);
                }
                else
                {
                    mMaxIndex++;
                    lEntry.Index = mMaxIndex;
                }
            }
        }