Re: stringOperand + null = ?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Mark Chambers <no_spam@xxxxxxxxxxx> wrote:
Hi there,

In the expression A + B where A is a string and B isn't, I know that
"B.ToString()" will be called and the results concatenated. If B is null
however does the standard guarantee that "String.Empty" will be used
instead. Thanks.

Yup, the spec says:

<quote>
If an operand of string concatenation is null, an empty string is
substituted. Otherwise, any non-string argument is converted to its
string representation by invoking the virtual ToString method inherited
from type object. If ToString returns null, an empty string is
substituted.
</quote>

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



Relevant Pages

  • Re: syntax...
    ... B&D on the part of the language designer. ... probably handle concatenation of string literals by itself, ... bitwise XOR, or if not that, then exponentiation.) ...
    (comp.lang.misc)
  • Bugs in the Module::Dependency
    ... Manifying blib/man1/pmd_indexer.plx.1 ... Use of uninitialized value in concatenation or string at ... # Failed test in t/04grapher.t at line 81. ...
    (perl.dbi.users)
  • RE: Simple regex problem has me baffled
    ... I am writing a script to analyse a log file. ... Each pair of Request and Response calls have a unique ... Use of uninitialized value in concatenation or string at ...
    (perl.beginners)
  • Re: Literal concatenation, strings vs. numbers (was: Numeric literals in other than base 10 - wa
    ... Well my take on it is that this would not be the same as string ... concatenation, the series of digits would be parsed as a single token ... digit separation can superficially resemble string concatenation if ... I would favor _ as a digit separator in Python ...
    (comp.lang.python)
  • Re: Simple regex problem has me baffled
    ... I am writing a script to analyse a log file. ... Each pair of Request and Response calls have a unique ... Use of uninitialized value in concatenation or string at ./magic.pl ...
    (perl.beginners)