Strings

String Variables in C#

Used to declare a variable which holds a string.


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

Notes

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.


Example
string Location = "Toronto, Ontario, Canada";

See Also
Documentation

Strings (C# Programming Guide - MSDN

Add to Slack

< Inheritance   |   String Length >

© 2018 SyntaxDB. All Rights Reserved.