Re: Console.WriteLine(s) Is Missing Line Terminator?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I thought they recommend the & operator for concatenating
strings in VB over the + operator.

When outputting strings, you could try using FormatString
instead.

Console.WriteLine(String.Format("Level = {0}, InfoString = {1}", _
Level, InfoString))

Robin S.
-------------------------------
"Gadget" <gadget@xxxxxxxxxx> wrote in message
news:b9nwslj796lu.hb3jongyckgb.dlg@xxxxxxxxxxxxx
On Sat, 18 Nov 2006 00:07:40 +0100, Mattias Sjögren wrote:

Also as a rule of thumb, avoid using '&' to concatenate strings, as it
has
a tendency to hide casting errors.

Huh? Can you give an example of that? And what do you suggest we use
instead? Hopefully not the + operator.

*Hopefully* not the + operator? I'm interested to know why you say that,
so
please let me know if I'm missing something :)

The '&' concatenation performs runtime casting of objects to strings, so
it
always calls the default ToString() method. It is better to perform this
cast implicitly at design time so you can also specify the format if
needed
by calling an integer's ToString method.
Yes, in VB6 it was slower to join strings with '+', but in VB.Net all
strings are internally joined this way anyway.

It's only in there for VB6 style compatibility,

No it certainly isn't.

OK, fire away Mattias, I am genuinely interested.

Cheers,
Gadget


.



Relevant Pages

  • Re: [PHP] PHP URL issues
    ... I have already tried different ways of producing output and I completely disagree that concatenating the pieces and then echoing them is the best. ... I found that echoing the separate parts as arguments to echo with commas in between was the fastest and variable interpolation within double quotes strings was fastest than concatenation. ... I am sure that some benchmarks are quite representative, ... Subject: [PHP] PHP URL issues ...
    (php.general)
  • Re: Myths of our time...
    ... >> task of concatenating thousands of strings is simply bad design, evne ... >> if you couldget away with it in some languages. ...
    (borland.public.delphi.non-technical)
  • Re: why no automatic conversion in string concatenation?
    ... explicitly convert non-string variables to strings when concatenating ... >>> print myBool ... or to put it more succinctly, because "explicit is better than implicit." ...
    (comp.lang.python)
  • Re: stringBuilder vs string concatenation myth of usage...
    ... cost with several times the cost - but both costs will be tiny. ... time concatenating strings, then even if you only need to concatenate ... batches of 100 strings at a time you'll find there's a very significant ... two calls to DateTime.Now and have them vary by only a nanosecond. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Beginner Variable Problem
    ... It's treating the input as strings and the + operator is concatenating the ... Dim Input1 As Double ... > Input2 = InputBox("Enter the second amount!") ...
    (microsoft.public.excel.programming)