#if NET20 using System.Collections.Generic; namespace System.Collections.Generic { /// /// Represents a set of values. /// /// The type of elements in the HashSet. public class HashSet : ICollection { private Dictionary _innerDictionary; /// /// Initializes a new instance of a HashSet /// that is empty and uses the default equality comparer for the set type. /// public HashSet() { _innerDictionary = new Dictionary(); } /// /// Adds the specified element to a HashSet. /// /// The element to add to the set. void ICollection.Add(T item) { AddInternal(item); } private void AddInternal(T item) { _innerDictionary.Add(item, false); } /// /// Adds the specified element to a HashSet. /// /// The element to add to the set. /// true if the element is added to the HashSet object; /// false if the element is already present. public bool Add(T item) { if (_innerDictionary.ContainsKey(item)) return false; AddInternal(item); return true; } /// /// Removes all elements from a HashSet. /// public void Clear() { _innerDictionary.Clear(); _innerDictionary = new Dictionary(); } /// /// Determines whether a HashSet contains the specified element. /// /// The element to locate in the HashSet. /// true if the HashSet contains the specified element; otherwise, false. public bool Contains(T item) { return _innerDictionary.ContainsKey(item); } /// /// Copies the elements of a HashSet to an array, starting at the specified array index. /// /// The one-dimensional array that is the destination of the elements copied from /// the HashSet. The array must have zero-based indexing /// The zero-based index in array at which copying begins. public void CopyTo(T[] array, int arrayIndex) { _innerDictionary.Keys.CopyTo(array, arrayIndex); } /// /// Gets the number of elements that are contained in a HashSet. /// public int Count { get { return _innerDictionary.Keys.Count; } } /// /// Gets a value indicating whether the HashSet is read-only. /// This property is always false. /// public bool IsReadOnly { get { return false; } } /// /// Removes the specified element from a HashSet. /// /// The element to remove. /// true if the element is successfully found and removed; otherwise, false. This /// method returns false if item is not found in the HashSet public bool Remove(T item) { return _innerDictionary.Remove(item); } /// /// Returns an enumerator that iterates through a HashSet. /// /// A HashSet.Enumerator object for the HashSet. public IEnumerator GetEnumerator() { return _innerDictionary.Keys.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } } #endif