日期:2014-05-19  浏览次数:20861 次

c#中的两个数值交换问题
c#中的两个数值交换问题新手提问,各位大哥大姐帮忙看看怎么回事!   谢谢!

最后的数值怎么交换不过来?     在线等!
using   System;      
class   Program
        {
                private   static   void   change(int   a,   int   b)
                {
                        int   c;
                        c   =   a;
                        a   =   b;
                        b   =   c;
                  }
          private       static   void   Main(string[]   args)
                {
                    Console.WriteLine( "please   input   a: ");
                        int   a=Convert.ToInt16(   Console.ReadLine());
                    Console.WriteLine( "please   input   b: ");
                        int   b=Convert.ToInt16(   Console.ReadLine());
                        change(a,b);
                        Console.WriteLine( "a={0},b={1} ",a,b);

                  }


                }


------解决方案--------------------
private static void change(ref int a, ref int b)
{
int c;
c = a;
a = b;
b = c;
}

change(ref a, ref b);