You can break the line into multiple lines, but I wouldn't say the syntax looks nice any more.
You need to use the $@
syntax to use an interpolated verbatim string, and you can place newlines inside the {...}
parameters, like this:
string s = $@"This is all {
10
} going to be one long {
DateTime.Now
} line.";
The string above will not contain any newlines and will actually have content like this:
This is all 10 going to be one long 01.08.2015 23.49.47 line.
(note, norwegian format)
Now, having said that, I would not stop using string.Format
. In my opinion some of these string interpolation expressions looks really good, but more complex ones starts to become very hard to read. Considering that unless you use FormattableString
, the code will be compiled into a call to String.Format
anyway, I would say keep going with String.Format
where it makes sense.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…