Implement Existing Interface In C#

  1. using System;  
  2. class Point: ICloneable // implementing IClonable Interface  
  3.     {  
  4.         public int x, y;  
  5.         public Point(int x, int y) {  
  6.             this.x = x;  
  7.             this.y = y;  
  8.         }  
  9.         public object Clone() {  
  10.             return new Point(this.x, this.y);  
  11.         }  
  12.         public override string ToString() {  
  13.             return ("X= " + x.ToString() + " Y= " + y.ToString());  
  14.         }  
  15.     }  
  16. class Porgram {  
  17.     static void Main(string[] args) {  
  18.         Point p1 = new Point(10, 10);  
  19.         Point p2 = (Point) p1.Clone();  
  20.         p2.x = 20;  
  21.         Console.WriteLine(p1);  
  22.         Console.WriteLine(p2);  
  23.         Console.ReadKey();  
  24.     }  
  25. }