The following code overloads the unary operator ++ to a rectangle object to increment the length and breadth of the rectangle object.
using System; class Rectangle//from w ww. j a v a2s . com { public double length, breadth; public Rectangle(double length, double breadth) { this.length = length; this.breadth = breadth; } public double AreaOfRectangle() { return length * breadth; } public static Rectangle operator ++(Rectangle rect) { rect.length++; rect.breadth++; return rect; } } class Program { static void Main(string[] args) { Rectangle rect = new Rectangle(5, 7); Console.WriteLine("Length={0} Unit Breadth={1} Unit", rect.length, rect.breadth); Console.WriteLine("Area of Rectangle={0} Sq. Unit", rect.AreaOfRectangle()); rect++; Console.WriteLine("Modified Length={0} Unit Breadth={1} Unit", rect.length, rect.breadth); Console.WriteLine("Area of new Rectangle={0} Sq. Unit", rect.AreaOfRectangle()); } }