Beispiel #1
0
        static void Main()
        {
            Vector v1 = new Vector(1, 32, 5);
            Vector v2 = new Vector(845.4, 54.3, -7.8);

            Console.WriteLine("\n In IJK format, \nv1 is {0,30:IJK}\nv2 is {1,30:IJK}", v1, v2);
            Console.WriteLine("\n In default format, \nv1 is {0,30}\nv2 is {1,30}", v1, v2);
            Console.WriteLine("\n In VE format, \nv1 is {0,30:VE}\nv2 is {1,30:VE}", v1, v2);
            Console.WriteLine("\nNorms are: \nv1 is {0,20:N}\nv2 is {1,20:N}", v1, v2);
        }
        private static void Main()
        {
            Vector vect1, vect2, vect3;

            vect1 = new Vector(3.5, 2.6, 2.2);
            vect2 = new Vector(2.4, 6.7, 8.3);
            vect3 = vect1 + vect2;

            Console.WriteLine("vect1 = {0}", vect1.ToString());
            Console.WriteLine("vect1 = {0}", vect2.ToString());
            Console.WriteLine("vect1 = {0}", vect3.ToString());

            Console.WriteLine("2 * vect3 = {0}",2 * vect3);

            vect3 += vect1;
            Console.WriteLine("vect3 += vect1 : {0}",vect3);

            double dot=vect1 * vect2;
            Console.WriteLine("vect1 * vect2 = {0}",dot);
        }
        // overload operator: +
        public static Vector operator +(Vector lhs, Vector rhs)
        {
            Vector result = new Vector(lhs);

            result.X += rhs.X;
            result.Y += rhs.Y;
            result.Z += rhs.Z;

            return result;
        }
 public Vector(Vector rhs)
 {
     this._x = rhs.X;
     this._y = rhs.Y;
     this._z = rhs.Z;
 }