Advertisement
AmidamaruZXC

Untitled

Jun 17th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BookstoreLibrary
  8. {
  9.     public class Product : IComparable<Product>
  10.     {
  11.         double _price;
  12.         string _title;
  13.  
  14.         public double Price
  15.         {
  16.             get => _price;
  17.             set
  18.             {
  19.                 if (value > 0)
  20.                     _price = value;
  21.                 else
  22.                     throw new ArgumentException("Стоимость должна быть положительной!");
  23.             }
  24.         }
  25.  
  26.         public string Title
  27.         {
  28.             get => _title;
  29.             set
  30.             {
  31.                 if (value != null && value != "")
  32.                     _title = value;
  33.                 else
  34.                     throw new ArgumentException("Название не может быть пустой строкой или значением null!");
  35.             }
  36.         }
  37.  
  38.  
  39.  
  40.         public int CompareTo(Product product) =>
  41.             Price.CompareTo(product.Price);
  42.  
  43.  
  44.         public override string ToString()
  45.         {
  46.             return $"Price = ${Price:F2}.";
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement