
传值调用与引用调用
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
}
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)