Question about '='

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Do the following strings of code perform the same operation?

num1 = num2

and

num2 = num1

If they don't, what is the difference between them? Thanks.
 
Xero said:
Do the following strings of code perform the same operation?

num1 = num2

and

num2 = num1

If they don't, what is the difference between them? Thanks.


No it's not the same.
Well, if your num1 = 8 and your num2 = 9 then the first string of code says:
num1 = num2 so it makes num1 equal to num2, so both are 9. The other formula
does it the other way around, so it makes num2 equal to num1, so the both
are 8.
Couln't you find that out yourself? No offence.

Jan K.
 
Jeff,

A little bit in addition to Jan

The = operater in VBNet has two meanings

An assignment
An evaluation

When it is precedent by "If" than it is an eveluation

If num1 = num2 is the same as
If nuw2 = num1

Keep track that an assignment of a value is about the value
The assignement of an object is about the reference address.

I hope this helps?

Cor
 
Xero said:
Do the following strings of code perform the same operation?

num1 = num2

and

num2 = num1

If they don't, what is the difference between them? Thanks.

In the first sample, 'num1' gets the value of 'num2', in the 2nd sample
'num2' gets the value of 'num1'.

So, no, it's not the same operation.

\\\
num1 = 1
num2 = 2
num1 = num2
///

.... results in 'num1' holding the value 2 and 'num2' holding the value 2.

\\\
num1 = 1
num2 = 2
num2 = num1
///

.... results in 'num1' holding the value 1 and 'num2' holding the value 1.
 
Cor Ligthert said:
The = operater in VBNet has two meanings

An assignment
An evaluation

When it is precedent by "If" than it is an eveluation

In addition to its logical usage as a comparison operator:

Public Function IsCaps(Test As String) As Boolean
Return (Test = Test.ToUpper)
End Function

LFS
 
When it is precedent by "If" than it is an eveluation

If num1 = num2 is the same as
If nuw2 = num1

I'm being overly pedantic here (and not useful to the OP), but the two
are the same in a boolean context only if the evaluation of the
arguments has no side effects.

I assume the evalution of the arguments within a boolean expression is
left-to-right, but I'm not sure that's actually documented/guaranteed
anyplace.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top