Created
May 24, 2016 13:34
-
-
Save arman-hpp/f05692467d32b129b8a7dfbc1fe20ae3 to your computer and use it in GitHub Desktop.
GenericCollection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericCollection<T> : ICollection<T> | |
{ | |
private readonly HashSet<T> _set; | |
public IEnumerator<T> GetEnumerator() | |
{ | |
return _set.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
public GenericCollection() | |
{ | |
_set = new HashSet<T>(); | |
} | |
public virtual void Add(T item) | |
{ | |
_set.Add(item); | |
} | |
public virtual void Clear() | |
{ | |
_set.Clear(); | |
} | |
public virtual bool Contains(T item) | |
{ | |
return _set.Contains(item); | |
} | |
public virtual void CopyTo(T[] array, int arrayIndex) | |
{ | |
_set.CopyTo(array, arrayIndex); | |
} | |
public virtual bool Remove(T item) | |
{ | |
return _set.Remove(item); | |
} | |
public int Count => _set.Count; | |
public bool IsReadOnly => false; | |
} | |
public class CustomerCollection : GenericCollection<Customer> | |
{ | |
public override void Add(Customer item) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment