一个关于输出型参数的算法,求教
public partial class index : System.Web.UI.Page
{
public string outtest(out string xx)
{
string me = "1234 ";
string bn = " ";
if (me != " ")
{
xx = me;
return xx;
}
if (bn != " ")
{
xx = bn;
return xx;
}
}
protected void Page_Load(object sender, EventArgs e)
{
lab();
}
public void lab()
{
string intcount;
index app = new index();
Label2.Text = app.outtest(out intcount).ToString();
}
}
程序很简单,就是关于调用输出参数xx,但是在if语句中是无法return的,求如何改,但是实现的功能是一样的,判断非空是肯定需要的
------解决方案--------------------输出类型得参数不需要调用return,楼主设计得方法有些问题。
------解决方案--------------------//直接返回值
public string outtest()
{
string me = "1234 ";
string bn = " ";
if (me != " ")
{
return me;
}
if (bn != " ")
{
return bn;
}
}
//调用
Label2.Text = app.outtest();
//如果一定要用out,就不要返回值
public void outtest(out string xx)
{
string me = "1234 ";
string bn = " ";
if (me != " ")
{
xx = me;
}
if (bn != " ")
{
xx = bn;
}
}
//调用
string intcount;
app.outtest(out intcount);
Label2.Text = intcount;
------解决方案--------------------public void outtest(out string xx)
{
string me = "1234 ";
string bn = " ";
if (me != " ")