| 代码说明一切,有问题请找我讨论。复制代码static void Main(string[] args)
        {
            #region ref关键字
            int a = 1;
            int b = 2;
            Console.WriteLine("Before AboutRef(): a = {0}, b = {1}", a, b);
            AboutRef(ref a, ref b); // 参数列表中的ref关键字是必须的。
            Console.WriteLine("              Now: a = {0}, b = {1}", a, b);
            #endregion
            #region out关键字
            int o = 1;
            Console.WriteLine("Before AboutOut(): o = {0}", o);
            AboutOut(out o); // 参数列表中的out关键字是必须的。
            Console.WriteLine("              Now: o = {0}", o);
            #endregion
        }
        static void AboutRef(ref int i1, ref int i2)
        {
            // 在这里,Test()中的i1和i2相当于a和b的别名,i1和i2的修改对a和b有效
            int temp = i1;
            i1 = i2;
            i2 = temp;
        }
        static void AboutOut(out int outI)
        {
            // outI相当于o的别名,outI的修改对o有效。但把他当作是未赋值的变量
            //int i1 = outI; // 现在outI相当于一个未赋值的变量,这将产生编译错误。我们知道,不能使用未赋值的变量。
            outI = 999;  // 必须对变量赋值,你才能使用他
            int i2 = outI;
        }
 |