Advertisement
NikiStoyanov05

Untitled

Jul 4th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace IteratorsAndComparators
  5. {
  6. public class StartUp
  7. {
  8. public static void Main()
  9. {
  10. Book bookOne = new Book("Animal Farm", 2003, "George Orwell");
  11. Book bookTwo = new Book("The Documents in the Case", 2002, "Dorothy Sayers", "Robert Eustace");
  12. Book bookThree = new Book("The Documents in the Case", 1930);
  13.  
  14. Library libraryOne = new Library();
  15. Library libraryTwo = new Library(bookOne, bookTwo, bookThree);
  16. }
  17. }
  18. public class Book
  19. {
  20. public string Title { get; set; }
  21. public int Year { get; set; }
  22. public List<string> Authors { get; set; }
  23. public Book(string title,int year, params string[] authors)
  24. {
  25. this.Title = title;
  26. this.Year = year;
  27. this.Authors = authors.ToList();
  28. }
  29. }
  30. class Library : IEnumerable<Book>
  31. {
  32. public List<Book> Books { get; set; }
  33. public Library(params Book[] books)
  34. {
  35. this.Books = books.ToList();
  36. }
  37.  
  38. public IEnumerator<Book> GetEnumerator()
  39. {
  40. foreach (var book in Books)
  41. {
  42. yield return book;
  43. }
  44. }
  45.  
  46. IEnumerator IEnumerable.GetEnumerator()
  47. {
  48. return this.GetEnumerator();
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement