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.

Community
  • 1
  • 1
Pascal
  • 12,265
  • 25
  • 103
  • 195
  • 2
    yes its a dupe, See [this](http://stackoverflow.com/a/288913/368070) answer on the same post. – gideon Jan 14 '12 at 19:33

1 Answers1

3

With literals, this is equivalent to:

string foo = "bar1bar2bar3";

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

Chris Shain
  • 50,833
  • 6
  • 93
  • 125