Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BookstoreLibrary
- {
- public class Product : IComparable<Product>
- {
- double _price;
- string _title;
- public double Price
- {
- get => _price;
- set
- {
- if (value > 0)
- _price = value;
- else
- throw new ArgumentException("Стоимость должна быть положительной!");
- }
- }
- public string Title
- {
- get => _title;
- set
- {
- if (value != null && value != "")
- _title = value;
- else
- throw new ArgumentException("Название не может быть пустой строкой или значением null!");
- }
- }
- public int CompareTo(Product product) =>
- Price.CompareTo(product.Price);
- public override string ToString()
- {
- return $"Price = ${Price:F2}.";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement