By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

Concatenation - String.Concat

P: n/a
Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?

Dim a As String = "bah"
Dim b As String = "bah2"
Dim c As String = a & b
Dim d As String = String.Concat(a, b)

string a = "bah";
string b = "bah2";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method when
the size/number of strings is unknown?

Thanks,
Mythran

Feb 6 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Mythran <ki********@hotmail.comREMOVETRAIL> wrote:
Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?

Dim a As String = "bah"
Dim b As String = "bah2"
Dim c As String = a & b
Dim d As String = String.Concat(a, b)

string a = "bah";
string b = "bah2";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method when
the size/number of strings is unknown?


They compile to the same code - the compiler uses String.Concat
internally. However, I believe that using the operator is usually more
readable than using string.Concat explicitly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 6 '06 #2

P: n/a
"Mythran" <ki********@hotmail.comREMOVETRAIL> schrieb:
Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?

Dim a As String = "bah"
Dim b As String = "bah2"
Dim c As String = a & b
Dim d As String = String.Concat(a, b)

string a = "bah";
string b = "bah2";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method
when


I suggest to use the '&' operator in the examples described above. This
will enable the compiler to concatenate string literals at compile time in
some cases such as '"Bla" & ControlChars.NewLine & "Goo"'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #3

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mythran <ki********@hotmail.comREMOVETRAIL> wrote:
Out of curiosity, only, which is recommended for SHORT concatenation...or
concatenating two or three strings that are relatively small in size?

Dim a As String = "bah"
Dim b As String = "bah2"
Dim c As String = a & b
Dim d As String = String.Concat(a, b)

string a = "bah";
string b = "bah2";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method
when
the size/number of strings is unknown?


They compile to the same code - the compiler uses String.Concat
internally. However, I believe that using the operator is usually more
readable than using string.Concat explicitly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Ok, thanks Jon.

Mythran

Feb 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.