调用时怎么数值没有变化?

changxiang 2003-02-17 12:19:34
using System;
namespace huan
{
public class getdata
{
public void getit(ref int a,ref int b)
{ int c=0;
if(a<b)
{ a=c;
b=a;
c=a;
Console.WriteLine("The two number that from big to small is:{0},{1}",a,b);
}
}
}
public class use
{
public static void Main()
{
int a=3,b=5;
getdata useit=new getdata();
useit.getit(ref a,ref b);
}
}


}
结果怎么是:
The two number that from big to small is:0,0
?????????????????
...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
joddy2003 2003-02-18
  • 打赏
  • 举报
回复
if(a<b)
{
a=c;
b=a;
c=a;
Console.WriteLine("The two number that from big to small is:{0},{1}",a,b);
}
这个IF语句有逻辑错误哟
Mynetstart 2003-02-17
  • 打赏
  • 举报
回复
在IF语句中改为如下:
if(a<b)
{
c=a;
a=b;
b=c;
Console.WriteLine("The two number that from big to small is:{0},{1}",a,b);
}
saucer 2003-02-17
  • 打赏
  • 举报
回复
try


public void getit(ref int a,ref int b)
{
int c=0;
if(a<b)
{
c=a;
a=b;
b=c;

}
Console.WriteLine("The two number that from big to small is:{0},{1}",a,b);
}

110,571

社区成员

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

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

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