关于 REF 参数问题:一段代码,运行结果不解

iamxia 2008-05-03 01:26:29
using System;
class Class1
{
static void F(ref int a, ref int b)
{
int s = 10;
s ++;
a = 20;
b = 30;
Console.WriteLine("a={0}, b={0}, s={0}",a,b,s);
}
static public void Main()
{
int s=100;
F(ref s, ref s);
Console.WriteLine("int s = {0}", s);
}
}


结果:
a=30, b=30, s=30
int s = 30

怎么F()里面的s结果也是30?
...全文
102 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
贫僧又回来了 2008-05-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Guyschaos 的回复:]
引用 1 楼 yunfeng007 的回复:
Console.WriteLine("a={0}, b={0}, s={0}",a,b,s);
这句错了
应该为
Console.WriteLine("a={0}, b={1}, s={2}",a,b,s);

等于没回答!
[/Quote]
看错了,呵呵!
iamxia 2008-05-03
  • 打赏
  • 举报
回复
的确犯了低级错误
贫僧又回来了 2008-05-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yunfeng007 的回复:]
Console.WriteLine("a={0}, b={0}, s={0}",a,b,s);
这句错了
应该为
Console.WriteLine("a={0}, b={1}, s={2}",a,b,s);
[/Quote]
等于没回答!
yunfeng007 2008-05-03
  • 打赏
  • 举报
回复
Console.WriteLine("a={0}, b={0}, s={0}",a,b,s);
这句错了
应该为
Console.WriteLine("a={0}, b={1}, s={2}",a,b,s);

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧