/// <summary> /// Performs an "exclusive-or" of the two SerializableLists, keeping only the elements that /// are in one of the SerializableLists, but not in both. The original SerializableLists are not modified /// during this operation. The result SerializableList is a <c>Clone()</c> of this SerializableList containing /// the elements from the exclusive-or operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <returns>A SerializableList containing the result of <c>a ^ b</c>.</returns> public virtual SerializableList <T> ExclusiveOr(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); foreach (T element in a) { if (resultSerializableList.Contains(element)) { resultSerializableList.Remove(element); } else { resultSerializableList.Add(element); } } return(resultSerializableList); }
/// <summary> /// Retains only the elements in this SerializableList that are contained in the specified collection. /// </summary> /// <param name="c">Collection that defines the SerializableList of elements to be retained.</param> /// <returns><c>true</c> if this SerializableList changed as a result of this operation.</returns> public bool RetainAll(SerializableList <T> c) { //Put data from C into a SerializableList so we can use the Contains() method. SerializableList <T> cSerializableList = new SerializableList <T>(c); //We are going to build a SerializableList of elements to remove. SerializableList <T> removeSerializableList = new SerializableList <T>(); foreach (T o in this) { //If C does not contain O, then we need to remove O from our //SerializableList. We can't do this while iterating through our SerializableList, so //we put it into RemoveSerializableList for later. if (!cSerializableList.Contains(o)) { removeSerializableList.Add(o); } } return(this.RemoveAll(removeSerializableList)); }