Advertisement
velio84

StudentClass

Jan 13th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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 Student
  8. {
  9.     class Student
  10.     {
  11.         public delegate void PropertyChange(string str);
  12.         public event PropertyChange ChangeEvent;
  13.  
  14.         private string name;
  15.         private string oldName;
  16.  
  17.         private int age;
  18.         private int oldAge;
  19.  
  20.         public Student(string name, int age)
  21.         {
  22.             this.Name = name;
  23.             this.Age = age;
  24.         }
  25.  
  26.         public string Name
  27.         {
  28.             get { return this.name; }
  29.             set
  30.             {
  31.                 if (value == null)
  32.                     throw new ArgumentNullException("You must enter a name! ");
  33.                 else if (this.name == null)
  34.                     this.name = value;
  35.                 else
  36.                 {
  37.                     this.oldName = name;
  38.                     this.name = value;
  39.                     if (ChangeEvent != null)
  40.                         ChangeEvent("Property changed: Name (from " + this.oldName + " to " + this.name + ")");
  41.                 }
  42.                
  43.             }
  44.         }
  45.  
  46.         public int Age
  47.         {
  48.             get { return this.age; }
  49.             set
  50.             {
  51.                 if (value < 1)
  52.                     throw new ArgumentOutOfRangeException("The age must be > 0 ");
  53.                 else if (this.age > 0)
  54.                 {
  55.                     this.oldAge = this.age;
  56.                     this.age = value;
  57.                     if (ChangeEvent != null)
  58.                         ChangeEvent("Property changed: Age (from " + this.oldAge + " to " + this.age + ")");
  59.                 }
  60.                 else
  61.                     this.age = value;
  62.             }
  63.         }
  64.  
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement