C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Step 1: A string reference is assigned the literal value "Dot Net ". The word "Perls" is appended to the string with the += operator.
String LiteralStep 2: We append a second word to the string. A new string is created, and the identifier "value" now points to it.
C# program that appends strings
using System;
class Program
{
static void Main()
{
string value = "Dot Net ";
// Step 1: append a word to the string.
value += "Perls";
Console.WriteLine(value);
// Step 2: append another word.
value += " Basket";
Console.WriteLine(value);
}
}
Output
The Dev Codes
The Dev Codes Basket
NewLine: We also see the Environment.NewLine property. This represents the newline sequence, which is 2 chars.
Environment.NewLinePropertyC# program that appends line to string
using System;
class Program
{
static void Main()
{
string value1 = "One";
string value2 = "Two";
// Append newline to string and also string.
value1 += Environment.NewLine + value2;
Console.WriteLine(value1);
}
}
Output
One
Two
However: It is fine to think of this code as string appending, because the end result is the same, regardless of implementation.