Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Concatenation Operators
  & Operator
  Syntax
  Parts
  Remarks
  See also
  + Operator
  Syntax
  Parts
  Result
  Supported Types
  Remarks
  Overloading
  See also
  Source/Reference

VB.NET Concatenation Operators

The supporting VB.NET Concatenation Operators are &, +.

& Operator

Generates a string concatenation of two expressions.

Syntax

result = expression1 & expression2  

Parts

result: Required. Any String or Object variable.

expression1: Required. Any expression with a data type that widens to String.

expression2: Required. Any expression with a data type that widens to String.

Remarks

If the data type of expression1 or expression2 is not String but widens to String, it is converted to String. If either of the data types does not widen to String, the compiler generates an error.

The data type of result is String. If one or both expressions evaluate to Nothing or have a value of DBNull.Value, they are treated as a string with a value of "".

Note

The & operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

Note

The ampersand (&) character can also be used to identify variables as type Long. For more information, see Type Characters.

See also

+ Operator

Addition operator. Adds two numbers or returns the positive value of a numeric expression. Can also be used to concatenate two string expressions.

Syntax

expression1 + expression2  
- or -  
+ expression1  

Parts

expression1: Required. Any numeric or string expression.

expression2: Required unless the + operator is calculating a negative value. Any numeric or string expression.

Result

If expression1 and expression2 are both numeric, the result is their arithmetic sum.

If expression2 is absent, the + operator is the unary identity operator for the unchanged value of an expression. In this sense, the operation consists of retaining the sign of expression1, so the result is negative if expression1 is negative.

If expression1 and expression2 are both strings, the result is the concatenation of their values.

If expression1 and expression2 are of mixed types, the action taken depends on their types, their contents, and the setting of the Option Strict Statement. For more information, see the tables in "Remarks."

Supported Types

All numeric types, including the unsigned and floating-point types and Decimal, and String.

Remarks

In general, + performs arithmetic addition when possible, and concatenates only when both expressions are strings.

If neither expression is an Object, Visual Basic takes the following actions.

Data types of expressions Action by compiler
Both expressions are numeric data types (SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong, Decimal, Single, or Double) Add. The result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Integer Arithmetic" tables in Data Types of Operator Results.
Both expressions are of type String Concatenate.
One expression is a numeric data type and the other is a string If Option Strict is On, then generate a compiler error.

If Option Strict is Off, then implicitly convert the String to Double and add.

If the String cannot be converted to Double, then throw an InvalidCastException exception.
One expression is a numeric data type, and the other is Nothing Add, with Nothing valued as zero.
One expression is a string, and the other is Nothing Concatenate, with Nothing valued as "".

If one expression is an Object expression, Visual Basic takes the following actions.

Data types of expressions Action by compiler
Object expression holds a numeric value and the other is a numeric data type If Option Strict is On, then generate a compiler error.

If Option Strict is Off, then add.
Object expression holds a numeric value and the other is of type String If Option Strict is On, then generate a compiler error.

If Option Strict is Off, then implicitly convert the String to Double and add.

If the String cannot be converted to Double, then throw an InvalidCastException exception.
Object expression holds a string and the other is a numeric data type If Option Strict is On, then generate a compiler error.

If Option Strict is Off, then implicitly convert the string Object to Double and add.

If the string Object cannot be converted to Double, then throw an InvalidCastException exception.
Object expression holds a string and the other is of type String If Option Strict is On, then generate a compiler error.

If Option Strict is Off, then implicitly convert Object to String and concatenate.

If both expressions are Object expressions, Visual Basic takes the following actions (Option Strict Off only).

Data types of expressions Action by compiler
Both Object expressions hold numeric values Add.
Both Object expressions are of type String Concatenate.
One Object expression holds a numeric value and the other holds a string Implicitly convert the string Object to Double and add.

If the string Object cannot be converted to a numeric value, then throw an InvalidCastException exception.

If either Object expression evaluates to Nothing or DBNull, the + operator treats it as a String with a value of "".

Note

When you use the + operator, you might not be able to determine whether addition or string concatenation will occur. Use the & operator for concatenation to eliminate ambiguity and to provide self-documenting code.

Overloading

The + operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

Source/Reference


©sideway

ID: 200800002 Last Updated: 2/8/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 149

Software

Application 198

Digitization 25

Latex 7

Manim 115

Numeric 19

Programming

Web 283

Unicode 494

HTML 65

CSS 58

ASP.NET 149

OS 389

DeskTop 7

Python 19

Knowledge

Mathematics

Formulas 8

Algebra 25

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Physics

Electric 27

Biology 1

Geography 1


Copyright © 2000-2020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019