Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: "RobinS" <RobinS@xxxxxxxxxxxxxxx>
- Date: Fri, 17 Nov 2006 22:14:28 -0800
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
.
- Follow-Ups:
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: Gadget
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- References:
- Console.WriteLine(s) Is Missing Line Terminator?
- From: Fir5tSight
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: Mattias Sjögren
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: Gadget
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: Mattias Sjögren
- Re: Console.WriteLine(s) Is Missing Line Terminator?
- From: Gadget
- Console.WriteLine(s) Is Missing Line Terminator?
- Prev by Date: Re: Console.WriteLine(s) Is Missing Line Terminator?
- Next by Date: Re: DataGridView - Differnt Column Widths
- Previous by thread: Re: Console.WriteLine(s) Is Missing Line Terminator?
- Next by thread: Re: Console.WriteLine(s) Is Missing Line Terminator?
- Index(es):
Relevant Pages
|