Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 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 ConsoleApplication144
  8. {
  9.     class MyClass
  10.     {
  11.         private int num, min, max;
  12.         public MyClass(int a, int b)
  13.         {
  14.             min = a;
  15.             max = b;
  16.             code = (max - min) / 2;
  17.         }
  18.         public int code
  19.         {
  20.             get
  21.             {
  22.                 return num;
  23.             }
  24.             set
  25.             {
  26.                 if (value < min)
  27.                     num = min;
  28.                 else if (value > max)
  29.                     num = max;
  30.                 else
  31.                     num = value;
  32.             }
  33.         }
  34.     }
  35.     class UsingProbs
  36.     {
  37.         static void Main(string[] args)
  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