2015年11月2日 星期一

C2_2

using System;
namespace C2_2
{
    public class TestRef
    {
        ///

        ///資料交換方法
        ///
        ///
        ///
        static void Swap(ref int x, ref int y)
        {
            int i = x;
            x = y;
            y = i;
        }
        public static void Main()
        {
            int x = 100;
            int y = 200;
            Console.WriteLine("交換前:x={0},y={1}", x, y);
            Swap(ref x, ref y);
            Console.WriteLine("交換後:x={0},y={1}", x, y);
        }
    }
}

沒有留言: