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

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication7
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int a = 10;
14             int b = 15;
15             Test(ref a, ref b);
16             Console.WriteLine("现在a的值是{0},b的值是{1}",a,b);
17             Console.ReadKey();
18         }
19 
20         static int Test(ref int a,ref int b)
21         {
22             int temp = a; 
23             a = b;
24             b = temp;
25             return 20;
26         }
27 
28 
29     }
30 }
原文地址:https://www.cnblogs.com/start-from-scratch/p/5058043.html