[m-rev.] diff: implement some formatting functions for .NET
Tyson Dowd
trd at cs.mu.OZ.AU
Tue Aug 28 20:48:23 AEST 2001
On 28-Aug-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> Also the StringBuilder class only allows one to build a string
> efficiently upto some maximum capacity. It *doesn't* dynamically expand
> the size of the string. The default capacity according to the
> documentation is 16 chars, so this code isn't very robust. What you
> should do is count up the length of the string, then allocate a string
> builder of the correct size, blah, blah, blah.
Actually, the documentation blathers on about doing this, and then it
turns out that Append and Insert methods adjust the Capacity of
StringBuilder "as needed".
In fact, the documentation says:
Additionally, you can use the read/write Capacity property to set the
maximum length of your object. The following code example uses the
Capacity property to define the maximum object length.
[C#]
MyStringBuilder.Capacity = 25;
[Visual Basic]
MyStringBuilder.Capacity = 25
Any attempt to expand the StringBuilder class beyond the maximum range
causes an ArgumentOutOfRangeException to be thrown.
But this is rubbish, as most (if not all) attempts to expand the
StringBuilder class beyond this range succeed -- even if I explicitly
set Capacity by hand, it is automatically expanded.
So thanks for the comment, but the code is correct and the documentation
is very misleading. In fact in other places the StringBuilder docs are
just wrong (or perhaps the implementation is broken?).
I've reported this to MS. I think the only hope for the documentation
of the entire class is if it is completely re-written.
Tyson.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list