Table of contents Home page
using System; public struct ComplexNumber : ICloneable { private double real; private double imaginary; public ComplexNumber(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } public object Clone() { return new ComplexNumber(this.real, this.imaginary); } override public string ToString() { return this.real.ToString() + (this.imaginary >= 0 ? "+" : "") + this.imaginary.ToString() + "i"; } } public class Program { public static void Main(string[] args) { ComplexNumber o = new ComplexNumber(5, -6); Console.WriteLine("Original object: {0}", o.ToString()); ComplexNumber clone = (ComplexNumber)o.Clone(); Console.WriteLine("Cloned object: {0}", o.ToString()); Console.ReadKey(); } }