Advertisement
Gillito

Untitled

Jul 20th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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 ConsoleApplication56
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Student student = new Student(17);
  14.             Console.WriteLine(student.GetAdultHood);
  15.             Console.WriteLine(student.SomeValue = 4);
  16.             student.ShowCount();
  17.         }
  18.     }
  19.  
  20.     class Student
  21.     {
  22.         private int _age;
  23.         private int _getterCount = 0;
  24.         private int _setterCount = 0;
  25.         private int _someValue;
  26.  
  27.         public Student(int age)
  28.         {
  29.             _age = age;
  30.         }
  31.  
  32.         public int CheckAge
  33.         {
  34.             get
  35.             {
  36.                 _getterCount += 1;
  37.                 return _age;
  38.             }
  39.            
  40.         }
  41.  
  42.         public int SomeValue
  43.         {
  44.             get { return SomeValue; }
  45.             set
  46.             {
  47.                 _setterCount += 1;
  48.                 _someValue = value;
  49.             }
  50.         }
  51.  
  52.         public string GetAdultHood
  53.         {
  54.             get
  55.             {
  56.                 _getterCount += 1;
  57.                 if (_age >= 18)
  58.                     return "Совершеннолетний";
  59.                 else
  60.                     return "Несовершеннолетний";
  61.             }
  62.         }
  63.  
  64.         public void ShowCount()
  65.         {
  66.             Console.WriteLine(_getterCount);
  67.             Console.WriteLine(_setterCount);
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement