String Variables in C#

Used to declare a variable which holds a string.

string stringName = "value";
///multi line string
string multiLineString = @"Line 1
Line 2";


The @ prefix makes the string something called a verbatim string. It preserves newline characters.

A string is technically an object, so its contents cannot be changed (immutable). 'Modifications' to strings actually create and return a new object to the existing string variable.

A string variable must be initialized with either a value (which will be permanent) or null (for later initialization).

'string' is an alias for the System.String class. System.String can be used, if preferred.

string Location = "Toronto, Ontario, Canada";

See Also

Strings (C# Programming Guide - MSDN

Add to Slack

< Inheritance   |   String Length >

© 2019 SyntaxDB. All Rights Reserved.