On Wed, 08 Oct 2008 11:26:01 -0700, Kevin Smith <no@spam.comwro te:
No, it wouldn't. Nor would it modify the String instance that s refers
to. Strings are immutable. They are _never_ modified, by any method.
Yes, the variable s is modified, so that it refers to a new instance of
the string with the whitespace removed. The original instance is not
modified.
Smack in the middle of the page documenting String.Trim(), there's a
clearly-marked "Note" answering exactly this question:
http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx
They do. None of them modify the actual instance.
I suppose you could argue that the method help in the IDE is wrong, but I
think it's simply so brief that it's ambiguous. The phrase "of this
instance" is simply telling you that you don't pass some other String
instance to the method, but rather it just operates on the instance used
to call the method.
Pete
According to the intellisense help, string.Trim() "Removes all occurances
or white space characters from the beginning and end of this instance."
>
However, the follow code does not appear to modify s.
>
s.Trim('\r');
or white space characters from the beginning and end of this instance."
>
However, the follow code does not appear to modify s.
>
s.Trim('\r');
to. Strings are immutable. They are _never_ modified, by any method.
While the follow code DOES modify s.
>
s = s.Trim(\r');
>
s = s.Trim(\r');
the string with the whitespace removed. The original instance is not
modified.
Smack in the middle of the page documenting String.Trim(), there's a
clearly-marked "Note" answering exactly this question:
http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx
I understand that the help text quoted above is for the version of this
method that takes no arguments. But I would assume that variations of
Trim
work the same fundamental way.
method that takes no arguments. But I would assume that variations of
Trim
work the same fundamental way.
I suppose you could argue that the method help in the IDE is wrong, but I
think it's simply so brief that it's ambiguous. The phrase "of this
instance" is simply telling you that you don't pass some other String
instance to the method, but rather it just operates on the instance used
to call the method.
Pete
Comment