示例#1
0
        /// <summary>
        /// Entry Point of Application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // int, double, struct type ==> value type
            int X1;

            X1 = 2;
            int X2;

            X2 = X1;
            X2 = -1;

            Console.WriteLine("{0} \n{1}", X1, X2);

            // class ==> reference type
            MyPoint_C p1;

            p1   = new MyPoint_C(); //Create a MyPoint_C object and assign it to p2
            p1.X = 2;
            p1.Y = 3;
            MyPoint_C p2;

            p2   = p1;
            p2.X = -1;
            p2.Y = -2;
            Console.WriteLine("{0},{1}", p1.X, p1.Y);
            Console.WriteLine("{0},{1}", p2.X, p2.Y);
            Console.Read();
        }
示例#2
0
        /// <summary>
        /// Entry Point of Application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // int, double, struct type ==> value type

            MyPoint_S sp1;

            sp1.X = 2;
            sp1.Y = 3;
            MyPoint_S sp2;

            sp2   = sp1;
            sp2.X = -1;
            sp2.Y = -2;
            Console.WriteLine("{0},  {1}", sp1.X, sp1.Y);
            Console.WriteLine("{0},  {1}", sp2.X, sp2.Y);
            // class ==> reference type
            MyPoint_C cp1;

            cp1   = new MyPoint_C(); //Create a MyPoint_C object and assign it to p2
            cp1.X = 2;
            cp1.Y = 3;
            MyPoint_C cp2;

            cp2   = cp1;
            cp2.X = -1;
            cp2.Y = -2;
            Console.WriteLine("{0},  {1}", cp1.X, cp1.Y);
            Console.WriteLine("{0},  {1}", cp2.X, cp2.Y);
            Console.Read();
        }
示例#3
0
        /// <summary>
        /// Entry Point of Application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // int, double, struct type ==> value type

            MyPoint_S p1;

            p1.X = 2;
            p1.Y = 3;
            Console.WriteLine("({0},{1})", p1.X, p1.Y);

            // class ==> reference type
            MyPoint_C p2;

            p2   = new MyPoint_C(); //Create a Point object and assign it to p2
            p2.X = 2;
            p2.Y = 3;
            Console.WriteLine("({0},{1})", p2.X, p2.Y);
            Console.Read();
        }
示例#4
0
 /// <summary>
 /// Method
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public double DistanceTo(MyPoint_C p)
 {
     return((this.X - p.X) * (this.X - p.X) + (this.Y - p.Y) * (this.Y - p.Y));
     //return (X - p.X) * (X - p.X) + (Y - p.Y) * (Y - p.Y);
 }