Why escape brackets (curly braces) in a format string in .NET are '{{' or '}} "not' \ {'or' \} '

The question is how-to-escape-brackets-curly-braces-in-a-format-string-in-net , but there is no description of the reason? why is {{either }}not \{or used \}.

eg. string s = String.Format("{{ hello to all }}"); why not use \{strings in a string as escape, for example:\b\n\t

** I want to know the reason for the depth or from the language **

+4
source share
1 answer

Format strings are interpreted at runtime (not at compile time)

# \{ \}, { } . string.Format , , , . {0}. \{ { , String.Format , {. , string.Format {{ {. }} }.

#:

- character literal escaping:   e.g. '\'', '\n', '\u20AC' (the Euro € currency sign), '\x9' (equivalent to \t))
- literal string escaping:  e.g. "...\t...\u0040...\U000000041...\x9..."
- verbatim string escaping: e.g. @"...""..."
- string.Format escaping:   e.g. "...{{...}}..."
- keyword escaping: e.g. @if (for if as identifier)
- identifier escaping:  e.g. i\u0064 (for id)
+11

Source: https://habr.com/ru/post/1543817/


All Articles