Summary#
An ordinary string treats \ as the start of an escape: "\n" is a newline, "\t" a tab. That is what you want
in prose and exactly what you do not want in a regular expression or a path, where a backslash is part of the
value. Prefixing the string with @ turns escape processing off for the whole literal.
Signature#
@"ORD-\d{6}" // a regular expression, written the way a regular expression is written
@"C:\logs\today.txt" // a path, with single backslashes
@"she said ""no""" // "" is one literal quote — the only sequence with a meaningDescription#
Inside @"…":
- A backslash is a backslash.
@"\d"is two characters. The same value written ordinarily is"\\d". ""is one quote character. It is the only two-character sequence that means something else, and it exists because a lone"has to be able to end the literal.- A newline is allowed. The literal runs until its closing quote, so it may span lines, and the line breaks are part of the value.
Everything else about the string is unchanged — it is the same type, usable anywhere a string is.
Interpolation is a separate prefix: $"…" substitutes {Holes}. The two are not combined today; build the value
with an ordinary interpolated string, or keep the pattern verbatim and interpolate around it.
Examples#
entity Shipment {
[MaxLength(64)] string Reference;
}
app.Memory = new MemoryConfig {
// Verbatim: the regular expression reads as a regular expression.
Identifiers = [ @"SHP-\d{6}", @"[A-Z]{3}-\d{4}" ]
};string PatternA() { return @"ORD-\d{6}"; } // verbatim — one backslash
string PatternB() { return "ORD-\\d{6}"; } // ordinary — the backslash is escaped
// Both return the six characters `ORD-\d{6}`; the first is the one you can read.See also#
- identifier patterns (app.Memory) — the identifier patterns this notation exists to make readable
- format specifiers —
$"…"interpolation and its{value:format}holes