The string data type in C# is used to store
string values, which are delimited by double quotes.
To concatenate strings we have the plus sign, or concatenation operator (+).
It also has an accompanying assignment operator (+=), which appends a string to another and
creates a new string. Note that although we can break a statement
across multiple lines we can’t break a string. Instead, we have to split it using the concatenation
operator. If we want to add newlines into the string itself we use the escape character
‘n’. This backslash notation is used to write special characters, such as the backslash
itself or double-quote. They also include the Unicode character notation for writing
any Unicode character. If we want the escape characters to be ignored
we can add an “@” symbol before the string. This can for example be used to make file
paths more readable. The way to compare two strings is simply by
using the equal operator (==). This won’t compare the memory addresses as in some other
languages such as Java. The string class has a lot of useful members
for getting and changing the string. For example, methods like Replace, Insert, and Remove.
An important thing to note however is that these methods returns a completely new string.
This is because the string class is immutable. Its content cannot be changed unless the string
is replaced. Because of the performance cost of replacing
a string we should instead use the StringBuilder class whenever we need to modify a string
several times. StringBuilder is a mutable string object and has several methods to manipulate
the actual content of a strings such as Append, Remove, and Insert. To convert it back into
a regular string we use the ToString method.