int toAdd = 0;
List<int> list = new List<int> {1500, 1500, 1200, 1200, 1100, 1100, 1100, 1100, 1000, 1000, 900, 900, 600, 600, 600, 600, 400, 400, 400, 400};
for (int i = 0; i < list.Count; i++)
{
if ((toAdd += list[i]) <= (3000 - list[i]))
{
此c#代码有效,但此vb代码无效:
Dim toAdd As Integer = 0
Dim list As New List(Of Integer)() From {1500, 1500, 1200, 1200, 1100, 1100, 1100, 1100, 1000, 1000, 900, 900, 600, 600, 600, 600, 400, 400, 400, 400}
For i As Integer = 0 To list.Count - 1
If (toAdd += list(i)) <= (3000 - list(i)) Then
我已经确定问题出在'+ ='运算符上,如果我删除了'='则可以正常运行。
vb.net处理'+ ='是否与c#不同?我不明白我应该如何在vb中的if语句中做我想做的事情。
最佳答案
这应该使您可以执行所需的操作。
Dim toAdd As Integer = 0
Dim list As New List(Of Integer)() From {1500, 1500, 1200, 1200, 1100, 1100, 1100, 1100, 1000, 1000, 900, 900, 600, 600, 600, 600, 400, 400, 400, 400}
For i As Integer = 0 To list.Count - 1
toAdd = toAdd + list(i)
If toAdd <= (3000 - list(i)) Then
关于c# - if语句内的等号运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34909325/