- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace test12
- {
- class Program
- {
- static void Main(string[] args)
- {
- //值传递变引用传递
- int x = 20, y = 30;
- swap(x, y);
- Console.WriteLine("x={0},y={1}",x,y);
- swap(ref x, ref y);
- Console.WriteLine("x={0},y={1}", x, y);
- Console.ReadKey();
- }
- static void swap(ref int x,ref int y)
- {
- int temp = x;
- x = y;
- y = temp;
- }
- static void swap(int x,int y)
- {
- int temp = x;
- x = y;
- y = temp;
- }
- }
- }
复制代码 out 需要从方法中获取多个返回值用,调用函数的时候它不需要赋初值哦,函数退出前一定要给out参赋值哦 |