Advertisement
Gillito

Untitled

Jul 20th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 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(5);
  14.             Console.WriteLine(student.GetAge);
  15.  
  16.             Student2 student2 = new Student2();
  17.             student2.CheckAge = 500;
  18.             Console.WriteLine(student2.CheckAge);
  19.         }
  20.     }
  21.  
  22.     class Student
  23.     {
  24.         public Student(int age)
  25.         {
  26.             GetAge = age;
  27.         }
  28.         public int GetAge { get; private set; }
  29.     }
  30.  
  31.     class Student2
  32.     {
  33.         private int _age;
  34.  
  35.         public int CheckAge
  36.         {
  37.             get
  38.             { return _age; }
  39.             set
  40.             {
  41.                 if (_age > 0)
  42.                     _age = value;
  43.                 else
  44.                     return;
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement