- C# HashSet2 to work exactly like the standard C# HashSet, not compiling
- public class HashSet2<T> : ICollection<T>
- {
- private Dictionary<T, Int16> dict;
- // code has been edited out of this example
- // see further on in the question for the full class
- public IEnumerator<T> GetEnumerator()
- {
- throw new NotImplementedException();
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return dict.GetEnumerator();
- }
- }
- 'HashSet2<T>' does not implement interface member
- 'System.Collections.IEnumerable.GetEnumerator()'.
- 'HashSet2<T>.GetEnumerator()' cannot implement
- 'System.Collections.IEnumerable.GetEnumerator()'
- because it does not have the matching return type of
- 'System.Collections.IEnumerator'
- public class HashSet2<T> : ICollection<T>
- {
- private Dictionary<T, Int16> dict;
- // Dictionary<T, bool>
- public HashSet2()
- {
- dict = new Dictionary<T, short>();
- }
- public HashSet2(HashSet2<T> from)
- {
- dict = new Dictionary<T, short>();
- foreach (T n in from)
- dict.Add(n, 0);
- }
- public void Add(T item)
- {
- // The key of the dictionary is used but not the value.
- dict.Add(item, 0);
- }
- public void Clear()
- {
- dict.Clear();
- }
- public bool Contains(T item)
- {
- return dict.ContainsKey(item);
- }
- public void CopyTo(
- T[] array,
- int arrayIndex)
- {
- throw new NotImplementedException();
- }
- public bool Remove(T item)
- {
- return dict.Remove(item);
- }
- public System.Collections.IEnumerator GetEnumerator()
- {
- return ((System.Collections.IEnumerable)
- dict.Keys).GetEnumerator();
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return ((IEnumerable<T>)
- dict.Keys).GetEnumerator();
- }
- public int Count
- {
- get {return dict.Keys.Count;}
- }
- public bool IsReadOnly
- {
- get {return false;}
- }
- }
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable)dict.Keys).GetEnumerator();
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return ((IEnumerable<T>)dict.Keys).GetEnumerator();
- }
- public IEnumerator GetEnumerator()
- {
- dict.Keys.GetEnumerator();
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return dict.Keys.GetEnumerator();
- }
- public IEnumerator GetEnumerator()
- {
- return (IEnumerator)dict.Keys.GetEnumerator();
- }
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return (IEnumerator<T>)dict.Keys.GetEnumerator();
- }