Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace IteratorsAndComparators
- {
- public class StartUp
- {
- public static void Main()
- {
- Book bookOne = new Book("Animal Farm", 2003, "George Orwell");
- Book bookTwo = new Book("The Documents in the Case", 2002, "Dorothy Sayers", "Robert Eustace");
- Book bookThree = new Book("The Documents in the Case", 1930);
- Library libraryOne = new Library();
- Library libraryTwo = new Library(bookOne, bookTwo, bookThree);
- }
- }
- public class Book
- {
- public string Title { get; set; }
- public int Year { get; set; }
- public List<string> Authors { get; set; }
- public Book(string title,int year, params string[] authors)
- {
- this.Title = title;
- this.Year = year;
- this.Authors = authors.ToList();
- }
- }
- class Library : IEnumerable<Book>
- {
- public List<Book> Books { get; set; }
- public Library(params Book[] books)
- {
- this.Books = books.ToList();
- }
- public IEnumerator<Book> GetEnumerator()
- {
- foreach (var book in Books)
- {
- yield return book;
- }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement