Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace Classwork
- {
- class BookList
- {
- HashSet<string> books = new HashSet<string>();
- public static BookList operator +(BookList bookList, string name)
- {
- BookList result = (BookList)bookList.MemberwiseClone();
- result.books.Add(name);
- return result;
- }
- public static BookList operator -(BookList bookList, string name)
- {
- BookList result = (BookList)bookList.MemberwiseClone();
- result.books.Remove(name);
- return result;
- }
- public static bool operator ==(BookList bookList, string name)
- {
- return bookList.books.Contains(name);
- }
- public static bool operator !=(BookList bookList, string name)
- {
- return !bookList.books.Contains(name);
- }
- public string this[int index]
- {
- get
- {
- var enumerator = books.GetEnumerator();
- bool isValue = false;
- for (int i = 0; i <= index; i++)
- isValue = enumerator.MoveNext();
- if (isValue)
- return enumerator.Current;
- else
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement