locked
What does "&=" mean in visual basic? RRS feed

  • Question

  • In this code

    For j As Integer=1 To 3
      row=""
      For k As Integer =1 To 3
         entry= j & "x" & k & "=" & (j*k)
         row &= entry & " "
      Next
      lstTable.Items.Add(row)
      

    What does this "&=" mean?

    Friday, October 3, 2014 11:02 PM

Answers

  • Taking the question at face value, &= means string concatenation.

    Do be aware that strings are immutable though. :)


    Still lost in code, just at a little higher level.

    :-)

    • Proposed as answer by Blackwood Friday, October 3, 2014 11:19 PM
    • Marked as answer by Xiaoyang Tang Friday, October 3, 2014 11:41 PM
    Friday, October 3, 2014 11:08 PM

All replies

  • Taking the question at face value, &= means string concatenation.

    Do be aware that strings are immutable though. :)


    Still lost in code, just at a little higher level.

    :-)

    • Proposed as answer by Blackwood Friday, October 3, 2014 11:19 PM
    • Marked as answer by Xiaoyang Tang Friday, October 3, 2014 11:41 PM
    Friday, October 3, 2014 11:08 PM
  • What does this "&=" mean?

    Reference is here:
    http://msdn.microsoft.com/en-us/library/fz1zs43f.aspx

    Friday, October 3, 2014 11:14 PM
  • Hi,

     It is used to concatenate Strings. If you have a string like Str = "A" and then used Str &= "B" then the string would be "AB". You can read about the Operators at the link below.   8)

    &= Operator


    If you say it can`t be done then i`ll try it

    Friday, October 3, 2014 11:14 PM
  • So for example the &= in the following snippet sets the variable str to "ABCDEF".

    Dim str As String = "ABC"
    str &= "DEF" 'Equivalent to str = str & "DEF"

    There are several operators in VB that consist of a simple operator followed by =. For example

    num += 1 'Same as num = num + 1
    num *= 2 'Same as num = num * 2

    • Marked as answer by Xiaoyang Tang Friday, October 3, 2014 11:40 PM
    • Unmarked as answer by Xiaoyang Tang Friday, October 3, 2014 11:40 PM
    Friday, October 3, 2014 11:19 PM
  • I  type the "&=" in search, and I get nothing, what is  the problem?
    Friday, October 3, 2014 11:39 PM
  • I  type the "&=" in search, and I get nothing, what is  the problem?

    What search? Did you use Google? Bing? Yahoo? MSDN? Other?

    Try this:

    http://lmgtfy.com/?q=msdn+visual+basic+operator+%26%3D

    Look at the pages linked, or page down about 3 pages and you should see:

    &= Operator (Visual Basic) - MSDN - Microsoft
    msdn.microsoft.com/en-us/.../fz1zs43f.asp...
    Microsoft Developer Network
    The element on the left side of the &= operator can be a simple scalar variable, a property,
    or an element of an array. The variable or property cannot be ...

    http://msdn.microsoft.com/en-us/library/fz1zs43f.aspx

    Just "&=" alone isn't specific enough for most searches, you need to narrow it.

    - Wayne



    Saturday, October 4, 2014 12:57 AM
  • The new shortcut operators include +=, -=, &=, and others.  They are exactly the same as (for example):

    numA = numA + anothernum
    numA += anothernum

    stringA = stringA & anotherstring
    stringA &= anotherstring

    Solitaire

    Saturday, October 4, 2014 3:32 PM
  • The new shortcut operators include +=, -=, &=, and others.  They are exactly the same as (for example):

    stringA = stringA & anotherstring
    stringA &= anotherstring


    It's worth bearing in mind, if accustomed to using these operators in other languages, that
    their use in VB is different. For example, the &= operator in C/C++/C# is the bitwise
    AND assignment operator, since in those languages the & is the bitwise AND operator.

    - Wayne

    Saturday, October 4, 2014 7:00 PM