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