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); }
}
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); }
}
15
please input b:
12
a=15,b=12
lz知道C++里的传值和引用吧?
{
int c;
c = a;
a = b;
b = c;
} change(ref a, ref b);