找if语句错误(c#)

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:59:32
为什么只有在if (Exists(mystr))为False时才执行if (string.Compare(moneyaa,moneylastaa)>0,
我要先执行者if (string.Compare(moneyaa,moneylastaa)>0判断。是不是哪里错了!

string mystr=this.MobileNumber.Text.ToString();
int MoneyLast=Convert.ToInt32(this.NetWorkLastMoney.Text.ToString());
moneyaa=this.MobileMoney.Text.ToString();
string moneylastaa=this.NetWorkLastMoney.Text.ToString();
if (string.Compare(moneyaa,moneylastaa)>0)
{
MessageBox.Show(this, "您输入的金额大于你的余额,请先充值后再缴费!");
}

if (Exists(mystr))
{
Addmobilemoney();
AddmobileUpdatemoney();
Response.Redirect("NetWorkDefault.aspx");
}
else
{
this.MobileNumber.Text="";
this.MobileMoney.Text="";
MessageBox.Show(this, "此号码不在些地区!");
}

Exists(mystr)使用来判断this.MobileNumber.Text是否存在的,如果不不存在的话,string.Compare(moneyaa,moneylastaa)的判断也没有意义了。

建议按照以下方法:
string mystr=this.MobileNumber.Text.ToString();

if (Exists(mystr))
{
int MoneyLast=Convert.ToInt32(this.NetWorkLastMoney.Text.ToString());
moneyaa=this.MobileMoney.Text.ToString();
string moneylastaa=this.NetWorkLastMoney.Text.ToString();
if (string.Compare(moneyaa,moneylastaa)>0)
{
MessageBox.Show(this, "您输入的金额大于你的余额,请先充值后再缴费!");
}
else
{
Addmobilemoney();
AddmobileUpdatemoney();
Response.Redirect("NetWorkDefault.aspx");
}
}
else
{
this.MobileNumber.Text="";
this.MobileMoney.Text="";
MessageBox.Show(this, "此号码不在些地区!");
}

语法上没有任何问题。 哪个在前面是逻辑上的问题。需要按照具体需要来安排。如果改变判断顺序可能在某些条件下会发生错误的。

不可能吧 逻辑上是没有错误的。

打个断点按F11逐句跟踪一下

NO