Advertisement
mrAnderson33

Untitled

Feb 22nd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace firstC____prog
  7. {
  8.     class product
  9.     {
  10.         public product(string str)
  11.         {
  12.             var arr = str.Split(' ');
  13.             var nType = int.Parse(arr[0]);
  14.             switch(nType)
  15.             {
  16.                 case 1:
  17.                     type = Type.phone;
  18.                     break;
  19.                 case 2:
  20.                     type = Type.tv;
  21.                     break;
  22.                 case 3:
  23.                     type = Type.clock;
  24.                     break;
  25.             }
  26.  
  27.             mark = arr[1];
  28.             cost = int.Parse(arr[2]);
  29.             warranty = byte.Parse(arr[3]);
  30.  
  31.             this.ObjectID = Guid.NewGuid();
  32.             this.SaleTime = DateTime.Now;
  33.         }
  34.         public Type type
  35.         {
  36.             get;
  37.             set;
  38.         }
  39.         public string mark
  40.         {
  41.             get;
  42.             set;
  43.         }
  44.         public int cost
  45.         {
  46.             get;
  47.             set;
  48.         }
  49.         public byte warranty
  50.         {
  51.             get;
  52.             set;
  53.         }
  54.         public Guid  ObjectID
  55.         {
  56.             get;
  57.             set;
  58.         }
  59.  
  60.         public DateTime SaleTime
  61.         {
  62.             get;
  63.             set;
  64.         }
  65.  
  66.     }
  67.  
  68.     enum Type
  69.     {
  70.         phone,
  71.         tv,
  72.         clock
  73.     }
  74. }
  75.  
  76.  
  77.  
  78.   public bool HasProductThisTipe(product[] arr, Type type, out int count )
  79.         {
  80.             int i=0;
  81.             foreach(var a in arr)
  82.             {
  83.                 if (a.type == type) i++;
  84.             }
  85.             count = i;
  86.             return count != 0 ? true : false;  
  87.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement