Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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 ConsoleApplication49
  8. {
  9. class MyClass
  10. {
  11. private int num, min, max;
  12.  
  13. public MyClass(int a,int b)
  14. {
  15. min = a;
  16. max = b;
  17. code = (max + min) / 2;
  18. }
  19.  
  20. public int code
  21. {
  22. get
  23. {
  24. return num;
  25. }
  26. set
  27. {
  28. if (value < min) num = min;
  29. else if (value > max) num = max;
  30. else num = value;
  31. }
  32. }
  33. }
  34.  
  35. class UsingProbs
  36. {
  37. static void Main()
  38. {
  39. MyClass obj = new MyClass(1, 9);
  40. Console.WriteLine("Свойство code:" + obj.code);
  41. obj.code = 7;
  42. Console.WriteLine("Свойство code:" + obj.code);
  43. obj.code = 20;
  44. Console.WriteLine("Свойство code:" + obj.code);
  45. obj.code = -10;
  46. Console.WriteLine("Свойство code:" + obj.code);
  47. Console.ReadKey();
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement