Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsolApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- Book firstBook = new Book("The Screwtape Letters", "C.S. Lewis", 12.99m);
- Book secondBook = new Book("The Great Gatsby", "F. Scott Fitzgerald", 6.99m);
- Book thirdBook = new Book("In Search of Lost Time", "Marcel Proust", 22.99m);
- Book fourthBook = new Book("Ulysses", " James Joyce", 18.45m);
- Book fifthBook = new Book("One Hundred Years of Solitude", "Gabriel Garcia Marquez", 2.33m);
- List<Book> library = new List<Book> { firstBook, secondBook, thirdBook, fourthBook, fifthBook };
- foreach (var book in library)
- {
- Console.WriteLine($"Name: {book.Name}; Author: {book.Author}; Price: {book.Price}lv.");
- }
- Console.WriteLine($"Book count: {Book.CountOfBooks}");
- }
- }
- class Book
- {
- public string Name { get; set; }
- public string Author { get; set; }
- public decimal Price { get; set; }
- public static int CountOfBooks { get; set; }
- public Book(string name, string author, decimal price)
- {
- this.Name = name;
- this.Author = author;
- this.Price = price;
- CountOfBooks++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment