Exemplo n.º 1
0
        public void Swap(ref RefSwap ob1, ref RefSwap ob2)
        {
            RefSwap t;

            t   = ob1;
            ob1 = ob2;
            ob2 = t;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            RefTest ob = new RefTest();

            int a = 10;

            Console.WriteLine("a before call: " + a);

            ob.Sqr(ref a);

            Console.WriteLine("a after call: " + a);

            ///////////////////////////////////////////////////

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


            ValeSwap ob_2 = new ValeSwap();

            int x = 10;
            int y = 20;

            Console.WriteLine("x and y before call: " + x + " " + y);

            ob_2.Swap(ref x, ref y);
            Console.WriteLine("x and y after call: " + x + " " + y);

            //////////////////////////////////////////////////////////

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


            Decompose ob_3 = new Decompose();
            int       i;
            double    f;

            i = ob_3.GetParts(10.125, out f);
            Console.WriteLine("Integer portion is " + i);
            Console.WriteLine("Fractional part is " + f);

            //////////////////////////////////////////////////

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Num ob_4 = new Num();
            int lcf, gcf;

            if (ob_4.HasComFactor(231, 105, out lcf, out gcf))
            {
                Console.WriteLine("Lcf of 231 and 105 is " + lcf);
                Console.WriteLine("Gcf of 231 and 105 is " + gcf);
            }
            else
            {
                Console.WriteLine("No common factor for 35 and 49.");
            }
            if (ob_4.HasComFactor(35, 51, out lcf, out gcf))
            {
                Console.WriteLine("Lcf of 35 and 51 " + lcf);
                Console.WriteLine("Gcf of 35 and 51 is " + gcf);
            }
            else
            {
                Console.WriteLine("No common factor for 35 and 51.");
            }

            /////////////////////////////////////////////////////

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();



            RefSwap r = new RefSwap(1, 2);
            RefSwap w = new RefSwap(3, 4);

            Console.Write("x before call: ");
            r.Show();
            Console.Write("y before call: ");
            w.Show();
            Console.WriteLine();

            r.Swap(ref r, ref w);

            Console.Write("x after call: ");
            r.Show();
            Console.Write("y after call: ");
            w.Show();
        }