写一方法来实现两个变量的交换。在主调函数中定义两个整型变量,并初始化,调用交换方法,实现这两个变量的交换。(使用ref参数)

时间:2023-03-09 03:32:59
写一方法来实现两个变量的交换。在主调函数中定义两个整型变量,并初始化,调用交换方法,实现这两个变量的交换。(使用ref参数)
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int a = ;
int b = ;
Test(ref a, ref b);
Console.WriteLine("现在a的值是{0},b的值是{1}",a,b);
Console.ReadKey();
} static int Test(ref int a,ref int b)
{
int temp = a;
a = b;
b = temp;
return ;
} }
}

相关文章