Exemplo n.º 1
0
        public static void Run()
        {
            StructAndClass.Vector v1;
            v1.X = 5;
            v1.Y = 10;
            StructAndClass.Vector v2 = v1;  // Value
            v2.X = 6;
            v2.Y = 12;
            Console.WriteLine("v1: X = " + v1.X + ", Y = " + v1.Y);
            Console.WriteLine("v2: X = " + v2.X + ", Y = " + v2.Y);

            StructAndClass.Point p1 = new StructAndClass.Point();
            p1.X = 11;
            p1.Y = 22;
            StructAndClass.Point p2 = p1;   // Reference
            p2.X = 15;
            p2.Y = 30;
            Console.WriteLine("p1: X = " + p1.X + ", Y = " + p1.Y);
            Console.WriteLine("p2: X = " + p2.X + ", Y = " + p2.Y);
            Console.WriteLine();

            p1 = null;
            UsingRef.ShallowCopy(p1);
            Console.WriteLine("p1: X = " + p1);
            UsingRef.CopyUsingRef(ref p1);
            Console.WriteLine("p1: X = " + p1.X + ", Y = " + p1.Y);
            Console.WriteLine();

            double num1 = 5.2, num2 = 2.3, result;

            if (UsingOut.Divide(num1, num2, out result))
            {
                Console.WriteLine(num1 + " / " + num2 + " = " + result);
            }
        }
Exemplo n.º 2
0
 public static void CopyUsingRef(ref StructAndClass.Point _point)
 {
     _point = new StructAndClass.Point()
     {
         X = 7,
         Y = 14
     };
 }
Exemplo n.º 3
0
 public static void ShallowCopy(StructAndClass.Point _point)
 {
     _point = new StructAndClass.Point()
     {
         X = 6,
         Y = 12
     };
 }