Skip to content

Strings

Mario Gutierrez edited this page Jan 7, 2017 · 2 revisions

Formatting

string.Format("{0} {1} {2}", a, b, c);
string.Format("{0:d9}", someNumber);

The second example shows how specific formatting can be applied. That is, limiting decimal place precision, padding, etc.

Verbatim Strings

With "verbatim" strings, no escaping is done (\n, \t, etc).

string v = @"This is a ""verbatim"" string. Backslashes, \, are not escaped.";

Interpolated Strings

.NET 4.6+

With "interpolated" strings, variables can be referenced in the string and filtered.

string p = $"myVariable has value {myVariable | expression}."

Clone this wiki locally