7

Possible Duplicate:
Does C# optimize the concatenation of string literals?

string foo = "bar1" + "bar2" + "bar3";

Does the c# compiler internally apply the string.Concat method ?

Then it would be better to use the + operator for the readability sake.

1
  • 2
    yes its a dupe, See this answer on the same post. Commented Jan 14, 2012 at 19:33

1 Answer 1

3

With literals, this is equivalent to:

string foo = "bar1bar2bar3";

No concatenation is performed- they are combined at compile time into a constant.

Sign up to request clarification or add additional context in comments.

2 Comments

I think he meant in a case where you'd say string foo = "bar: " + bar + " (bar bar)"; where bar is unknown at compile time.
Possibly, but he didn't write the question that way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.