fork download
  1. using static System.Console;
  2.  
  3. class Complex {
  4. private int real;
  5. private int imaginary;
  6. public Complex(int i, int j) {
  7. real = i;
  8. imaginary = j;
  9. }
  10. public override bool Equals(object o) => ((Complex)o).real == this.real && ((Complex)o).imaginary == this.imaginary;
  11. public override string ToString() => string.Format("{0} + {1}i", real, imaginary);
  12. public override int GetHashCode() => this.ToString().GetHashCode();
  13. public static bool operator == (Complex x, Complex y) => x.Equals(y);
  14. public static bool operator != (Complex x, Complex y) => !x.Equals(y);
  15. public static Complex operator +(Complex x, Complex y) => new Complex(x.real + y.real, x.imaginary + y.imaginary);
  16. }
  17. public class Program {
  18. public static void Main() {
  19. var x = new Complex(10,20);
  20. WriteLine(x);
  21. var y = new Complex(10,20);
  22. WriteLine(y);
  23. var z = y;
  24. WriteLine(z);
  25. if (x == y) WriteLine("z igual y");
  26. else WriteLine("x diferente y");
  27. if (y != z) WriteLine("y diferente z");
  28. else WriteLine("y igual z");
  29. }
  30. }
  31.  
  32. //https://pt.stackoverflow.com/q/89577/101
Success #stdin #stdout 0.02s 15804KB
stdin
Standard input is empty
stdout
10 + 20i
10 + 20i
10 + 20i
z igual y
y igual z