Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the c# compiler concat strings [duplicate]

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.

like image 336
Pascal Avatar asked Jan 14 '12 19:01

Pascal


1 Answers

With literals, this is equivalent to:

string foo = "bar1bar2bar3";

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

like image 154
Chris Shain Avatar answered Oct 05 '22 13:10

Chris Shain