Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Box : IEnumerable
- {
- private List<PrintEdition> books = new List<PrintEdition>();
- public Box()
- {
- books.Add(new Book("Биба", 15, 2, 3, true));
- books.Add(new Book("Боба", 40, 22, 5, true));
- books.Add(new Journal("Вообще не книга", 3, 20, 4, 5));
- books.Add(new CopyBook("Какой-то мусор", 60, 66, 9, 6));
- }
- #region IEnumenator Members
- public IEnumerator GetEnumerator()
- {
- return new BoxEnumerator(books);
- }
- #endregion
- public void DeleteAt(int position)
- {
- books.Remove(books.ElementAt(position));
- }
- public void Add(PrintEdition item)
- {
- books.Add(item);
- }
- }
- public class BoxEnumerator : IEnumerator
- {
- private List<PrintEdition> books;
- public BoxEnumerator(List<PrintEdition> books)
- {
- this.books = books;
- }
- int position = -1;
- public object Current
- {
- get
- {
- if (position == -1 || position > books.Count)
- {
- throw new InvalidOperationException();
- }
- return books.ElementAt(position);
- }
- }
- public bool MoveNext()
- {
- if (position < books.Count - 1)
- {
- position++;
- return true;
- }
- return false;
- }
- public void Reset()
- {
- position = -1;
- }
- }
- class NameComparer : IComparer<PrintEdition>
- {
- public int Compare(PrintEdition x, PrintEdition y)
- {
- PrintEdition t1 = (PrintEdition)x;
- PrintEdition t2 = (PrintEdition)y;
- return String.Compare(t1.name, t2.name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement