Verbatim string literals

just a newby at c# and unity. In lecture 30 about word wrapping i have a question:

isn´t much easier to use a verbatim string literal instead of concatenating long text strings?

code should look something like this

text.text @“hello blablavbla
blablabla
bla-bla-bla”;

for me it works but i don’t now if this a recommendable

I think this completely depends on the context. I don’t think there’s any run-time difference between the two forms, just compile-time, so it’s whatever suits the circumstance better. Imagining you wanted a numbered list - 1.\n2\n3\n4\n5\n6\n is a lot more terse than

@"1.
2.
3.
4.
5.
6."

So ultimately it’s whatever suits your needs in the particular context best. I think in terms of “is this recommendable”, people generally end up picking one and using it almost exclusively. If it’s consistent and the code is readable, whatever works best for you is best!

Thanks toby

Privacy & Terms