When we use curly braces in the string.Format its not working in C#?

3 votes
273 views
Tarun Gautam asked 20-Dec-2017 in programming by Tarun Gautam
edited 20-Dec-2017 by Tarun-Gautam

When we use curly braces in the string.Format its not working in C#?

below is my code:

string functionName="Add";

string.Format("function {0}(args) { return false; }", functionName);

Please help me!.

1 Answer

2 votes
Pawan Shukla answered 20-Dec-2017 by Pawan Shukla

Hi Tarun,

I just want to let you know that you are doing simple mistake as you are applying "{return false;}" but actually you should apply "{{ return fasle ;}}". it will definitely work!!.

string functionName="Add";

string.Format("function {0}(args) {{ return false; }}", functionName);