在VB.net没有增量运算符 [英] No increment operator in VB.net
问题描述
我是相当新的vb.net和碰到这个问题,而在C#转换for循环VB.net
我意识到,增量运营商都没有在vb.net(++和 - )
,而我却能它像做 CNT + = 1
I am fairly new to vb.net and came across this issue while converting a for loop in C# to VB.net
I realized that the increment operators are not available in vb.net (++ and --)
whereas i was able it do something like cnt +=1
我研究了一下, 在同一Eric的帖子,但没有真正能够完全理解它。
他提到的在VB中,一个语句不能只是一个表情。不知道如何真正结合使用。
I researched a bit and came across Eric's post on the same, but wasn't really able to understand fully on it. He mentions of In VB, a STATEMENT cannot be just an EXPRESSION. not sure how that really fits in.
我希望有人在这里将能够解释为什么这并不以相同的方式工作,因为它在C#一样。
(希望这也将举行真正在我们为什么 ==
在C#中比较)
I hope someone here would be able to explain why this doesn't work in the same way as it does in C#.
(Hope this will also hold true as in why we have ==
in C# for comparison)
推荐答案
我要说的是语言设计者简单地认为基本
比℃,更好的基线
设计时视觉BASIC
。您可以按照 C
(和前面, BCPL
)通过 C ++ 的血统code>,
的Java
和 C#
。
I would say that the language designers simply thought that BASIC
was a better baseline than C
when designing Visual BASIC
. You can follow the lineage of C
(and, earlier, BCPL
) through C++
, Java
and C#
.
在 VB
血统来自于原来的基本
达特茅斯(以及更早,的Fortran
),是一个不同的野兽完全。
The VB
lineage comes from the original BASIC
from Dartmouth (and, earlier, Fortran
) and is a different beast altogether.
在换句话说,开始作为久负盛名的基本
:
In other words, what started as the venerable BASIC
:
LET I = I + 1
可能已经被黑客攻击并摧毁的足够的: - )
has probably been hacked and destroyed enough :-)
根据Eric的帖子,我++;
确实只是产生 I
与 I <表达式一/ code>在事件发生后递增(
我++;
是一个表达式,就像无副作用表达我;
)。
As per Eric's post, i++;
is indeed just an expression, one that yields i
with the side effect that i
is incremented after the event (i++;
is an expression, just like the non-side-effect expression i;
).
这是因为 C
允许这些赤裸裸的表情,甚至东西像 42
这并没有真正做很多,但也完全有效。换句话说,下面是一个完整的 C
程序:
That's because C
allows these naked expressions, even things like 42;
which doesn't really do much but is perfectly valid. In other words, the following is a complete C
program:
int main (void) { 1; 2; 3; 4; 5; 6; 7; 8; 9; return 0; }
所有这些表达式是有效的,但没有用。
All those expressions are valid but useless.
在基本
,这是不是真的做了,因为基本
组成的的语句的(事情做了)。这就是为什么 I + = 1
(增加声明我
)被认为是犹太但我++
(一种表达什么都不做这恰好有一个副作用,这增加 I
)不是。你可以说,这只是语义吹毛求疵,毫无疑问的 VB
设计者们争辩。
In BASIC
, this was not really done, because BASIC
consisted of statements (things that did something). That's why i += 1
(a statement incrementing i
) is considered kosher but i++
(an expression doing nothing which just happens to have a side effect which increments i
) isn't. You could argue that it's just semantic hair-splitting and no doubt the VB
designers did argue.
但该集团赢得了当天的都是我们不需要任何讨厌的 C
在我们敬爱的语言组。
But the group that won the day were the "we don't need no stinkin' C
in our beloved language" group.
你应该感谢小怜悯,至少你不必应付COBOL:
You should be thankful for small mercies, at least you're not having to deal with COBOL:
ADD 1 TO DD_WS_I.
这篇关于在VB.net没有增量运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!