/// <summary> /// 从集合中移除使用指定键的特定项目。 /// </summary> /// <param name="key">键。</param> /// <param name="value">项目。</param> /// <returns></returns> public bool Remove(TKey key, TValue value) { if (this.Items.ContainsKey(key)) { RepeatSortedDictionary <TKey, TValue> .Item tmp = this.Items[key]; EqualityComparer <TValue> valueComparer = EqualityComparer <TValue> .Default; bool r; if (valueComparer.Equals(tmp.Value, value)) { r = this.Items.Remove(key); if (tmp.HasSubItems) { this.Items.Add(key, new RepeatSortedDictionary <TKey, TValue> .Item(tmp.SubItems.First.Value)); tmp.SubItems.RemoveFirst(); RepeatSortedDictionary <TKey, TValue> .Item newItem = this.Items[key]; newItem._SubItems = tmp.SubItems; } } else { r = tmp.SubItems.Remove(value); } if (r) { this._Count--; } return(r); } return(false); }
/// <summary> /// 从集合中移除第一个项目。 /// </summary> /// <returns></returns> public void RemoveFirst() { if (this.Count > 0) { SortedDictionary <TKey, RepeatSortedDictionary <TKey, TValue> .Item> .Enumerator tmp2 = this.Items.GetEnumerator(); tmp2.MoveNext(); var tmp = tmp2.Current; bool r = this.Items.Remove(tmp.Key); if (r) { if (tmp.Value.HasSubItems) { this.Items.Add(tmp.Key, new RepeatSortedDictionary <TKey, TValue> .Item(tmp.Value.SubItems.First.Value)); tmp.Value.SubItems.RemoveFirst(); RepeatSortedDictionary <TKey, TValue> .Item newItem = this.Items[tmp.Key]; newItem._SubItems = tmp.Value.SubItems; } this._Count--; } } }
/// <summary> /// 从集合中移除与指定键匹配的项目。 /// </summary> /// <param name="key"></param> /// <returns></returns> public bool Remove(TKey key) { if (this.Items.ContainsKey(key)) { RepeatSortedDictionary <TKey, TValue> .Item tmp = this.Items[key]; bool r = this.Items.Remove(key); if (r) { if (!tmp.HasSubItems) { this._Count--; } else { this._Count = this._Count - tmp.SubItems.Count - 1; } } return(r); } return(false); }