[VB.NET Tips] assignment operator must pay attention

Assignment operator is a statement that can not be used in the expression, the expression is equal to the equal sign indicates the assignment instead.

On example:

    Dim x As Integer
    Dim y As Object

    x = 5
    y = x = 5

    Console.WriteLine(y)
    Console.Read()

In this example, the first statement assigns 5 x, the second statement, the first equal sign is the assignment. And the second equal sign is the same.
Thus the statement first calculating x is equal to 5, and the results (True) to the variable y.

This is important to note, otherwise, there may be side effects can not be captured in the code.

Guess you like

Origin www.cnblogs.com/tengwei6328/p/11261488.html