
传值调用与引用调用
1
using System;
2
3
class MethodCall
4

{
5
public static void Main()
6
{
7
/**//*
8
* 参数类型分为 in, ref, out 三种,默认为 in。
9
* in 类型在子方法中修改了对应变量后,主方法中的值不会发生改变。
10
* ref 类型在子方法中修改了对应变量后,主方法中的值也会发生改变。
11
* out 主方法中对应的变量不需要初始化。
12
*
13
*/
14
int a = 3, b = 4, c;
15
Console.WriteLine("Before Method Call : a = {0}, b = {1}, c 未赋值", a, b);
16
AMethod(a, ref b, out c);
17
Console.WriteLine("After Method Call : a = {0}, b = {1}, c = {2}", a, b, c);
18
}
19
20
public static void AMethod(int x, ref int y, out int z)
21
{
22
x = 7;
23
y = 8;
24
z = 9;
25
}
26
}
转载于:https://www.cnblogs.com/geovindu/archive/2005/12/19/300521.html