469,607 Members | 1,986 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

VB equivalent of this C# code

what is vb equiv. of

++

shown in C# ?
Oct 16 '06 #1
6 1842
i ++ in VB is i += 1 or i = i + 1
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Jon Paal" wrote:
what is vb equiv. of

++

shown in C# ?
Oct 16 '06 #2

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
what is vb equiv. of

++

shown in C# ?
David's answer is correct, but with the ++ (increment) and -- (decrement)
operators, you also need to be aware that the ++ and -- operators each come
in two versions, prefix and postfix, that affect operation in complex
expressions.

int i = 5;
i++; and
++i; do exactly the same thing, add 1 to the current value in the variable
i.

i--; and
--i; also do exactly the same thing, subtract 1 from the current value in i.

So, prefix vs. postfix notation makes no difference in simple expressions.

In an expression like this, however,

Assume i == 5
if (i++ 5) vs. if(++1 5).

there is a difference:
if(i++ 5) evaluates the Boolean expression based on the *current* value in
i, then adds 1 to i.
The Boolean expression is false.

if(++1 5) *first* adds 1 to i, then evaluates the Boolean expression using
the new value in i.
The Boolean expression is true.

As you didn't show the context in which you encountered the ++ in C# code, I
though you should be aware of the difference between prefix and postfix
notation.
Oct 17 '06 #3
So when you take it all into consideration, there is no single statement
equivalent to statements containing ++ or --, since VB doesn't allow
assignments within expressions (there is a complex multi-statement equivalent
however). There is only a single statement equivalent for simple "i++" or
"i--" statements.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"pvdg42" wrote:
>
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
what is vb equiv. of

++

shown in C# ?
David's answer is correct, but with the ++ (increment) and -- (decrement)
operators, you also need to be aware that the ++ and -- operators each come
in two versions, prefix and postfix, that affect operation in complex
expressions.

int i = 5;
i++; and
++i; do exactly the same thing, add 1 to the current value in the variable
i.

i--; and
--i; also do exactly the same thing, subtract 1 from the current value in i.

So, prefix vs. postfix notation makes no difference in simple expressions.

In an expression like this, however,

Assume i == 5
if (i++ 5) vs. if(++1 5).

there is a difference:
if(i++ 5) evaluates the Boolean expression based on the *current* value in
i, then adds 1 to i.
The Boolean expression is false.

if(++1 5) *first* adds 1 to i, then evaluates the Boolean expression using
the new value in i.
The Boolean expression is true.

As you didn't show the context in which you encountered the ++ in C# code, I
though you should be aware of the difference between prefix and postfix
notation.
Oct 17 '06 #4
Jon,

I know it only on one place and that is in a "for index".

step 1

Cor

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot comschreef in bericht
news:ef**************@TK2MSFTNGP04.phx.gbl...
what is vb equiv. of

++

shown in C# ?

Oct 17 '06 #5
c#code :

if (failureCount++ >= MaxInvalidPasswordAttempts) {...

source of c# is example here:

http://www.eggheadcafe.com/articles/20051119.asp
Oct 19 '06 #6
David Anton wrote:
So when you take it all into consideration, there is no single statement
equivalent to statements containing ++ or --, since VB doesn't allow
assignments within expressions (there is a complex multi-statement equivalent
however). There is only a single statement equivalent for simple "i++" or
"i--" statements.
Well, if you *really*, *really* want it, nothing but common sense
forbids you from having:

<air-code>
Function PreInc(ByRef Value As Integer) As Integer
Value +=1
Return Value
End Function

Function PostInc(ByRef Value As Integer) As Integer
Dim Result As Integer = Value
Value +=1
Return Result
End Function

Function PreDec(ByRef Value As Integer) As Integer
Value -=1
Return Value
End Function

Function PostDec(ByRef Value As Integer) As Integer
Dim Result As Integer = Value
Value -=1
Return Result
End Function
</air-code>

Regards,

Branco.

Oct 19 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Edward WIJAYA | last post: by
8 posts views Thread by Xucyr | last post: by
9 posts views Thread by Alan Silver | last post: by
48 posts views Thread by Daniel Crespo | last post: by
14 posts views Thread by grid | last post: by
22 posts views Thread by Kurien Mathew | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.