R.D
R.D

Reputation: 4861

How to include parenthesis for AS-IS output in format string

I want to see, Hello {} in the output, but the following gives compiler errors

Console.WriteLine("{0} \{\}", "Hello");

Upvotes: 2

Views: 921

Answers (3)

Anthony Pegram
Anthony Pegram

Reputation: 126884

Console.WriteLine("{0} {{}}", "Hello");

Upvotes: 1

Adriaan Stander
Adriaan Stander

Reputation: 166406

You need to use double parenthesis.

Something like

string s = String.Format("{0} {{}}", "Hello"); 

First question at

String Formatting FAQ

Upvotes: 5

user180100
user180100

Reputation:

Using double brackets. See How to escape braces (curly brackets) in a format string in .NET for example.

Upvotes: 2

Related Questions