I am wondering what is the ‘best practice’ to break long strings in C# source code. Is this string
'string1'+ 'string2'+ 'string3'
concatenated during compiling or in run time?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s done at compile time. That’s exactly equivalent to ‘string1string2string3’.
Suppose you have:
The compiler will perform appropriate interning such that x and y refer to the same objects.
EDIT: There’s a lot of talk about
StringBuilderin the answers and comments. Many developers seem to believe that string concatenation should always be done withStringBuilder. That’s an overgeneralisation – it’s worth understanding whyStringBuilderis good in some situations, and not in others.