如何让1个方法返回多个值?
本帖最后由 YJDP0918 于 2013-04-28 18:48:00 编辑 本人写了1个程序,实现:根据用户在页面上输入的字符串的第1个字符返回多个值。
用户输入abc 则 返回 大写的首字符 和1
用户输入basdas 则 返回 大写的首字符 和2
用户输入不是a和b字母开头的字符 则返回 大写的首字母 和 3
下面是我的代码
txtChange(sourceString)的方法在下面没有写出,因为只有1句转换字符大小写的代码。
返回多个值的问题已解决,但是我不知道怎么去获取,
protected void btnChangeString_Click(object sender, EventArgs e)
{
txtNewAddress.Text = StringConverter.checkString(txtSourceString.Text.Trim());
}
int TypeID=999;
txtNewAddress.Text = StringConverter.checkString(txtSourceString.Text.Trim(),out TypeID);
多个返回值 方法
public static string checkString(string address, out int txtTypeID)
{
string addressTpye = address.Substring(0, 1).ToLower();
if (addressTpye == "a")
{
txtTypeID =1;
return txtChange(sourceString);
}
else
{
if (addressTpye == "b")
{
txtTypeID =2;
return txtChange(sourceString);
}
else
{
txtTypeID =3;
return txtChange(sourceString);
}
}
public string[] checkString(string txtvalue)
{
string[] txtchange = new String[2];
string addressTpye = txtvalue.Substring(0, 1).ToLower();
if (addressTpye == "a")
{
txtchange[0] = "1";
txtchange[1] = "A";
}
else
{
if (addressTpye == "a")
{
txtchange[0] = "2";
txtchange[1] = "B";
}
else
{
//......
}
}
return txtchange;
}