Section 5.2. Concatenation Operators


5.2. Concatenation Operators

Concatenation operators connect two source string expressions together and return a single string joined from the two original strings. Because strings in .NET are immutable, the returned string is always a completely new string instance.


& (String Concatenation)

The string concatenation operator returns a concatenated string from two source string expressions. Any non-string source expression is first converted to a string prior to concatenation (even if OptionStrict is set to On).

     result = expression1 & expression2 


+ (Addition)

When the addition operator is used with string operands, it concatenates the operands instead of adding their values. However, using this operator for concatenation can make the source code unclear, especially when using the new .NET-recommended variable naming conventions. If you mix string and numeric operands, this operator may also cause compile-time or runtime errors, depending on the content of the operands. For the clearest code, use the & concatenation operator instead.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net