|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Concatenation - String.Concatconcatenating 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 Mythran <kip_potter@hotmail.comREMOVETRAIL> wrote:
Show quoteHide quote > Out of curiosity, only, which is recommended for SHORT concatenation...or They compile to the same code - the compiler uses String.Concat > 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? 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
Show quote
Hide quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message Ok, thanks Jon.news:MPG.1e519c637d669ac398cddb@msnews.microsoft.com... > Mythran <kip_potter@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 Mythran
Show quote
Hide quote
"Mythran" <kip_potter@hotmail.comREMOVETRAIL> schrieb: I suggest to use the '&' operator in the examples described above. This > 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 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/>
For each
Windows Shell Integration: how? Visual Basic 2005 CreateFile File is busy Outlook Add-In: msoControlEdit: Textbox loses text when losing focus Problems with FileAccess and PcitoreBox VB.NET - How do I set and keep data in the clipboard? convert text to access mdb Structured files in VS 2005 Dynamic Insert Statment |
|||||||||||||||||||||||