SHARE
TWEET

Untitled

a guest Feb 14th, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Security.Cryptography.X509Certificates;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     public delegate void sa(Item item);
  10.  
  11.     public static class Manager
  12.     {
  13.         public static void Decrease(Item item)
  14.         {
  15.             item.Price /= 2;
  16.         }
  17.     }
  18.     public class Item
  19.     {
  20.         public event sa Decrease;
  21.         public  int ID { get; set; }
  22.         public  string Name { get; set; }
  23.         public  int Price { get; set; }
  24.  
  25.         public override string ToString()
  26.         {
  27.             return $"id - {ID}   name - {Name} price - {Price}";
  28.         }
  29.  
  30.         public override int GetHashCode()
  31.         {
  32.             return ID;
  33.         }
  34.     }
  35.  
  36.     public  class Shop:IEnumerable
  37.     {
  38.         public static Queue<Item> Items{get;private set; }
  39.  
  40.         public Shop()
  41.         {
  42.             Items=new Queue<Item>();
  43.         }
  44.  
  45.         public void Clear()
  46.         {
  47.             Items.Clear();
  48.         }
  49.  
  50.         public void Add(Item item)
  51.         {
  52.             Items = this + item;
  53.         }
  54.  
  55.         public void Remove()
  56.         {
  57.             Items= this - Items.Last();
  58.         }
  59.  
  60.         public IEnumerator GetEnumerator()
  61.         {
  62.             var enumerator = Items.GetEnumerator();
  63.             return enumerator;
  64.         }
  65.  
  66.  
  67.         public static Queue<Item> operator +(Shop shop, Item item)
  68.         {
  69.             var newQueue = Items;
  70.             newQueue.Enqueue(item);
  71.             return newQueue;
  72.         }
  73.  
  74.         public static Queue<Item> operator -(Shop shop, Item item)
  75.         {
  76.             var newQueue=Items;
  77.             newQueue.Dequeue();
  78.             return newQueue;
  79.         }
  80.     }
  81.     public class Program
  82.     {
  83.         static void Main(string[] args)
  84.         {
  85.             var firstItem = new Item() {ID = 1, Name = "item1", Price = 10};
  86.             var secondItem = new Item() { ID = 2, Name = "item2", Price = 5 };
  87.             var thirdItem = new Item() { ID = 3, Name = "item3", Price = 15 };
  88.             var fourthItem = new Item() { ID = 4, Name = "item4", Price = 13 };
  89.             var fifthItem = new Item() { ID = 5, Name = "item5", Price = 26 };
  90.             var shop=new Shop();
  91.             shop.Add(firstItem);
  92.             shop.Add(secondItem);
  93.             shop.Add(thirdItem);
  94.             shop.Add(fourthItem);
  95.             shop.Add(fifthItem);
  96.             foreach (var item in shop)
  97.             {
  98.                 Console.WriteLine(item.ToString());
  99.             }
  100.         }
  101.     }
  102.  
  103.  
  104. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top