alexivanov2003

Books

Feb 19th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsolApp
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.            
  11.             Book firstBook = new Book("The Screwtape Letters", "C.S. Lewis", 12.99m);
  12.             Book secondBook = new Book("The Great Gatsby", "F. Scott Fitzgerald", 6.99m);
  13.             Book thirdBook = new Book("In Search of Lost Time", "Marcel Proust", 22.99m);
  14.             Book fourthBook = new Book("Ulysses", " James Joyce", 18.45m);
  15.             Book fifthBook = new Book("One Hundred Years of Solitude", "Gabriel Garcia Marquez", 2.33m);
  16.             List<Book> library = new List<Book> { firstBook, secondBook, thirdBook, fourthBook, fifthBook };
  17.  
  18.             foreach (var book in library)
  19.             {
  20.                 Console.WriteLine($"Name: {book.Name}; Author: {book.Author}; Price: {book.Price}lv.");
  21.             }
  22.             Console.WriteLine($"Book count: {Book.CountOfBooks}");
  23.         }
  24.     }
  25.     class Book
  26.     {        
  27.         public string Name { get; set; }
  28.         public string Author { get; set; }
  29.         public decimal Price { get; set; }
  30.         public static int CountOfBooks { get; set; }
  31.  
  32.         public Book(string name, string author, decimal price)
  33.         {
  34.             this.Name = name;
  35.             this.Author = author;
  36.             this.Price = price;
  37.             CountOfBooks++;
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment