static void Main(string[] args)
        {
            ComplexNumber z1 = new ComplexNumber(2, 4);
            ComplexNumber z2 = new ComplexNumber(3, -2);
            ComplexNumber somma = z1 + z2;

            ComplexNumber sommaint = 10 + z1;

            if (somma)
            {
                Console.WriteLine("La somma ha parte reale o immaginaria diverse da zero");
            }
            else Console.WriteLine("somma nulla");

            if (z1 > z2)
            {
                Console.WriteLine("{0}>{1}", z1, z2);
            }

            double d = 1;
            //conversione esplicita da double a ComplexNumber
            ComplexNumber zd = (ComplexNumber)d;
            //conversione esplicita da ComplexNumber a int
            int real = (int)zd;

            //conversione implicita da ComplexNumber a int
            int[] array = zd;
        }
Example #2
0
 private static void Cast()
 {
     var complex = new ComplexNumber(2, 1);
     var real    = (double)complex; // 2
     //double real = complex; // 2
 }
Example #3
0
 private static void Unary()
 {
     var complex1 = new ComplexNumber(2, 1);
     var complex  = -complex1; // -2-i
 }
Example #4
0
 private static void AddReal()
 {
     var complex1 = new ComplexNumber(2, 1);
     var complex  = complex1 + 5; // 7+i
 }
 public ComplexNumber Add(ComplexNumber z1, ComplexNumber z2)
 {
     return new ComplexNumber(z1.real + z2.real, z1.imaginary + z2.imaginary);
 }
 public ComplexNumber Add(ComplexNumber z1, ComplexNumber z2)
 {
     return(new ComplexNumber(z1.real + z2.real, z1.imaginary + z2.imaginary));
 }