正在加载图片...
public class Complex C:\Windows\system32\cmd.exe 回x 9 e1:1+2i 10 private int real; c2:3+4i public int Real 3:4+6i 11 青按任意键继续, 12 { 13 get {return real; 14 set real value; 15 16 private int imaginary; 11 static void Main(string args) 17 public int Imaginary 12 18 { 13 Complex c1=new Complex(1,2); 19 get {return imaginary; 14 Complex c2 new Complex(3,4); set imaginary value; 15 Complex c3=c1 c2; 21 Console.WriteLine("c1:"+c1); public Complex(int real,int imaginary) 17 Console.WriteLine("c2:"+c2); 23 { 18 Console.WriteLine("c3:"+c3); this.real =real; 19 this.imaginary =imaginary; 26 } 27 public static Complex operator +(Complex c1,Complex c2) 28 { 29 Complex c3=new Complex(c1 .Real +c2.Real,c1 .imaginary +c2.imaginary ) 30 return c3; 32 } 3 public override string ToString() 34 35 return string.Format("0+(1)i",this .Real ,this.imaginary ) 36 37 16 16 运算符重载
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有