这段代码哪里错了哟????

AKULAKK 2009-05-14 04:45:51
private void button22_Click(object sender, System.EventArgs e)
{
string x = "MM";
int y = 12;
increase(x);
increase(y);
MessageBox.Show(x);
MessageBox.Show(y.ToString());

}

private void increase(ref object x)
{
if(x == System.Type.GetType("string"))
x = "QQ";
else
x = 13;
}

咋个实现修改x y的值哦?
...全文
150 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
SQL77 2009-05-14
  • 打赏
  • 举报
回复
若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字!!!引用型参数!!
unityql 2009-05-14
  • 打赏
  • 举报
回复
还怀疑什么,就是3楼的!
csz_1987 2009-05-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yzy8788 的回复:]
引用 4 楼 zhangxinxiao999 的回复:
若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字


是这样的吗?
怀疑一下
[/Quote]

不用怀疑。是这样的。
shangwei97 2009-05-14
  • 打赏
  • 举报
回复
二楼的正确
stevehxh 2009-05-14
  • 打赏
  • 举报
回复
方法的参数是ref,调用者也要显式使用ref~
yzy8788 2009-05-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhangxinxiao999 的回复:]
若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字
[/Quote]

是这样的吗?
怀疑一下
zhangxinxiao999 2009-05-14
  • 打赏
  • 举报
回复
若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字
ljhcy99 2009-05-14
  • 打赏
  • 举报
回复
private void button22_Click(object sender, System.EventArgs e)
{
string x = "MM";
int y = 12;
x= increase(x).ToString();
y = Convert.ToInt32(increase(y));
MessageBox.Show(x);
MessageBox.Show(y.ToString());

}

private object increase(object x)
{
if (x.GetType().Name.ToLower() == "string")
x = "QQ";
else
x = 13;
return x;
}
cppfaq 2009-05-14
  • 打赏
  • 举报
回复
private void button22_Click(object sender, System.EventArgs e)
{
object x = "MM";
object y = 12;
increase(ref x);
increase(ref y);
MessageBox.Show(x);
MessageBox.Show(y.ToString());

}


private static void increase(ref object x)
{
if (x.GetType() == Type.GetType("System.String"))
x = "QQ";
else
x = 13;
}
zhangxinxiao999 2009-05-14
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)
{
string x = "MM";
object x1 = x;
int y = 12;
object y1 = y;
increase( ref x1);
increase(ref y1);
MessageBox.Show(x);
MessageBox.Show(y.ToString());

}

110,537

社区成员

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

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

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