+ 1

C# which notation is better

$@"{sth here}/sth here" or String.Format("{0}/sth here", sth here)?

19th Oct 2017, 4:29 PM
Kacper Piotrowski
Kacper Piotrowski - avatar
2 Respuestas
+ 2
There is no better, it is just personal preference. The $ should be easier to read and make you look young I have to admit, I prefer the {0} since I have use it for so long. So {0} make you look old or should I say more experienced. please remove the space between "sth" and "here". "sth here" is not a valid integer. string sthhere = "hello"; Console.WriteLine($@"{sthhere}/sth here"); Console.WriteLine(String.Format("{0}/sth here", sthhere));
19th Oct 2017, 9:37 PM
sneeze
sneeze - avatar
+ 6
@sneeze was correct as it's just a syntactic sugar. Just pick one that you find easier to read and you'll be fine. P/S: The @ is superfluous in this case as it's used for verbatim string to simplify escape characters. 😉
20th Oct 2017, 5:21 AM
Zephyr Koo
Zephyr Koo - avatar