Implentation Of Properties

  1. using System;  
  2. class point {  
  3.     int getx, gety;  
  4.     //Property definition  
  5.     public int x {  
  6.         get {  
  7.             return getx;  
  8.         } //get property  
  9.         set {  
  10.             getx = value;  
  11.         } // set property  
  12.     }  
  13.     public int y {  
  14.         get {  
  15.             return gety;  
  16.         }  
  17.         set {  
  18.             gety = value;  
  19.         }  
  20.     }  
  21. }  
  22. class Program {  
  23.     static void Main(string[] args) {  
  24.         point start = new point();  
  25.         point end = new point();  
  26.         //Property Usage  
  27.         start.x = 10;  
  28.         start.y = 20;  
  29.         end.x = 100;  
  30.         end.y = 200;  
  31.         Console.Write("\npoint 1 :" + start.x + " " + end.x);  
  32.         Console.Write("\npoint 2 :" + start.y + " " + end.y);  
  33.         Console.ReadKey();  
  34.     }  
  35. }