Concatenation Operator (+)

Summary

Joins two strings.

Syntax

expression1 + expression2

Parameters

expression1
An expression that evaluates to the string type.
expression2
An expression that evaluates to the string type.

Description

For string data, the + operator joins two strings. For example, "abc" + "def" will evaluate to the combined string result "abcdef".

Differences from JavaScript

  • For strings, + results in concatenation. In JavaScript, concatentation occurs even if the other expression is numeric. Thus, 3 + "2" yields "32"; meanwhile, all other arithmetic operations yield NaN when applied to strings. In JS++, + is the only legal arithmetic operator for strings and is used for concatentation. All other arithmetic operators are not allowed for strings.

Examples

Basic Usage
1
2
3
4
5
import System;
 
Console.log("a" + "b"); // "ab"
Console.log("abc" + "def"); // "abcdef"
Console.log("foo" + "bar"); // "foobar"

See Also

Share

HTML | BBCode | Direct Link