C# 无效的表达式项';其他';
我是C#的初学者-我只学了几天。我想做一个GW2交易站计算器,但我被卡住了。我试图检查字符串的长度是否等于3,如果是aC# 无效的表达式项';其他';,c#,if-statement,C#,If Statement,我是C#的初学者-我只学了几天。我想做一个GW2交易站计算器,但我被卡住了。我试图检查字符串的长度是否等于3,如果是a-(如-21),则int的值为负值。我似乎很难看出我的else语句哪里出了问题 sellPrice = sellPrice * 0.85; profit = (int)sellPrice - buyPrice; String copperString; copperString = profit.ToString(
-
(如-21
),则int的值为负值。我似乎很难看出我的else
语句哪里出了问题
sellPrice = sellPrice * 0.85;
profit = (int)sellPrice - buyPrice;
String copperString;
copperString = profit.ToString();
int length = copperString.Length;
if (length == 3 && profit < 0);
{
copperString = copperString.Substring(Math.Max(0, copperString.Length - 3));
this.textBox3.Text = copperString;
}
else
{
copperString = copperString.Substring(Math.Max(0, copperString.Length - 2));
this.textBox3.Text = copperString;
}
sellPrice=sellPrice*0.85;
利润=(int)卖出价-买入价;
铜线;
铜线=利润。ToString();
整数长度=铜线长度;
如果(长度=3,利润<0);
{
铜串=铜串子串(数学最大值(0,铜串长度-3));
this.textBox3.Text=铜线;
}
其他的
{
copperString=copperString.Substring(数学最大值(0,copperString.Length-2));
this.textBox3.Text=铜线;
}
删除代码>在<代码>如果-->如果(长度==3和利润<0)
以下是完整的代码:
sellPrice = sellPrice * 0.85;
profit = (int)sellPrice - buyPrice;
String copperString;
copperString = profit.ToString();
int length = copperString.Length;
if (length == 3 && profit < 0)
{
copperString = copperString.Substring(Math.Max(0, copperString.Length - 3));
this.textBox3.Text = copperString;
}
else
{
copperString = copperString.Substring(Math.Max(0, copperString.Length - 2));
this.textBox3.Text = copperString;
}
sellPrice=sellPrice*0.85;
利润=(int)卖出价-买入价;
铜线;
铜线=利润。ToString();
整数长度=铜线长度;
如果(长度=3&&利润<0)
{
铜串=铜串子串(数学最大值(0,铜串长度-3));
this.textBox3.Text=铜线;
}
其他的
{
copperString=copperString.Substring(数学最大值(0,copperString.Length-2));
this.textBox3.Text=铜线;
}
这是因为代码>。应该是
if (length == 3 && profit < 0)
{
//TODO:
}
else
{
//TODO:
}
if(长度==3&&profit<0)
{
//待办事项:
}
其他的
{
//待办事项:
}
终止if()
语句,以及else
语句成为非法的“悬空”else语句后
删除代码>之后
if(长度=3&&profit<0)代码>从第行中删除分号if(长度==3&&price<0)
代码将被编译。感谢您的帮助:)@alanmgilvray在您认为最有帮助的答案左侧的大复选框上打勾,表示该答案已被接受,问题已得到回答;为了奖励回答者。还需要等待2分钟,但是我会:)这跟地狱有什么关系?然而,这是一个典型的typo.Np。请记住,若调试器给您提供了非常荒谬的报告,或者更大量的代码带有下划线,请控制“;”和“()”s。