C# 方法参数

来源:互联网 发布:列宁格勒号驱逐舰数据 编辑:程序博客网 时间:2024/06/03 16:59
class Program
    {
        static void Swap(ref int x, ref int y)
        {
            int temp = x;
            x = y;
            y = temp;
        }
        static void Swap(int x, int y)
        {
            int temp = x;
            x = y;
            y = temp;
        }
        static void Main(string[] args)
        {
            int i = 1, j = 2;
            Swap(i, j);
            Console.WriteLine("i={0},j={1}", i, j);
            Swap(ref i, ref j);
            Console.WriteLine("i={0},j={1}", i, j);
            Console.Read();
        }
    }
原创粉丝点击