- 打卡等级:常驻代表
- 打卡总天数:34
- 打卡月天数:6
- 打卡总奖励:9027
- 最近打卡:2025-12-17 23:15:51
管理员
- 积分
- 22569
|
参数按址传递需要用到 ref 关键字,ref 标识的参数可以改变参数的原始值。
- static void Main(string[] args)
- {
- string a = "0";
- int b = 0;
-
- Console.WriteLine("调用函数前");
- Console.WriteLine("a: {0}",a);
- Console.WriteLine("b: {0}", b);
-
- Test(ref a, ref b);
-
- Console.WriteLine("");
- Console.WriteLine("调用函数后");
- Console.WriteLine("a: {0}", a);
- Console.WriteLine("b: {0}", b);
-
- Console.Read();
- }
-
- static void Test(ref string a, ref int b)
- {
- a = "001";
- b = 100;
- }
复制代码
来源:C#社区
原文:https://www.hicsharp.com/a/d88e30b8cdac4da499dc8cd72a3d2d2f
|
|