Actually these both operators & and + are used to concatenate the more than one strings together to make a single string. it is required for printing function.
The syntax to use these two concatenation operators is given as:
S1="my"
S2="name"
We can concatenate these strings S1and S2 by using the + and & operators as:
S3=S1+S2
OR
S3=S1&S2
If both the operands that need to be concatenated are of string type then any of these two operators can be used interchangeably.
But in the case where both operators are of different types then + operator for concatenation will create an error.
Let consider there are two operands (one of string type and other of integer type) need to be concatenated as:
S3="HELLO" + 12
In the above case, visual basic first tries to convert the string operand ("HELLO") to its numeric code and then add it to the integer value 12.Thus, a type mismatch error will be generated at execution time. As, Plus sign (+) is also used in arithmetic operations thus if we use it for string concatenation as well, it will create an ambiguity for readers.So, we normally prefer the ampersand sign as a string concatenation operator.
The syntax to use these two concatenation operators is given as:
S1="my"
S2="name"
We can concatenate these strings S1and S2 by using the + and & operators as:
S3=S1+S2
OR
S3=S1&S2
If both the operands that need to be concatenated are of string type then any of these two operators can be used interchangeably.
But in the case where both operators are of different types then + operator for concatenation will create an error.
Let consider there are two operands (one of string type and other of integer type) need to be concatenated as:
S3="HELLO" + 12
In the above case, visual basic first tries to convert the string operand ("HELLO") to its numeric code and then add it to the integer value 12.Thus, a type mismatch error will be generated at execution time. As, Plus sign (+) is also used in arithmetic operations thus if we use it for string concatenation as well, it will create an ambiguity for readers.So, we normally prefer the ampersand sign as a string concatenation operator.