|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
String ConcatenationIn VB6, we were encouraged never to use "+" to concatenate strings, due to issues arisiing from Variants. We wre encouraged to use "&" instead. Since .NET doesn't allow Variants, in your opinion, is it still good programming practice to use either: String.Concat("a", "b") or "a" & "b" Or are we now allowed to use "a" + "b" as well. What has your experience been? TIA, -- Joe Hi Joe,
If you set Option Strict On, you can use safely "+" since the compiler will spot the wrong operations. Also, if you are concatenating a lot, use the System.Text.StringBuilder class instead. -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Joe" <J**@discussions.microsoft.com> escribió en el mensaje news:13866040-E1E9-4873-995C-1B27F622BAE4@microsoft.com... > Hello All: > > In VB6, we were encouraged never to use "+" to concatenate strings, due to > issues arisiing from Variants. We wre encouraged to use "&" instead. > > Since .NET doesn't allow Variants, in your opinion, is it still good > programming practice to use either: > > String.Concat("a", "b") > or > "a" & "b" > > Or are we now allowed to use "a" + "b" as well. > > What has your experience been? > > TIA, > -- > Joe > If you set Option Strict On, you can use safely "+" since the compiler However if that is Off you can not safe use it, therefore go on using that > will > spot the wrong operations. > &, it is probably more documentative for VB programmers as well. Just my thought, Cor Hi Cor,
Yes, I also recommend to use "&" to concatenate strings and in the same way "Option Strict On". -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> escribió en el mensaje news:%23H5lsEUPGHA.2628@TK2MSFTNGP15.phx.gbl... > However if that is Off you can not safe use it, therefore go on using that > &, it is probably more documentative for VB programmers as well. > > Just my thought, > > Cor "Joe" <J**@discussions.microsoft.com> schrieb: The recommendation of using '&' instead of '+' still stands. For matters of > In VB6, we were encouraged never to use "+" to concatenate strings, due to > issues arisiing from Variants. We wre encouraged to use "&" instead. > > Since .NET doesn't allow Variants, in your opinion, is it still good > programming practice to use either: > > String.Concat("a", "b") > or > "a" & "b" readability and potential compile time optimization I'd chosse the latter of the two samples you gave above. Note behavior differences with 'Option Strict On' and 'Option Strict Off'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Invalid Cast Exception using Inherited Object
DateTimePicker - Howto set the language PC to PC file transfer Save and Load a TreeView to SQL Database Referencing the Assembly GUID Client- Server Programming using VB.NEt & SQL SERVER How to hide the dialog form? Limit Columns shown from XML file OLE Container Ip Address vs Server Name |
|||||||||||||||||||||||