Re: String empty test
From: James Hebben (james.hebben_at_extraview.co.uk_nospam)
Date: 03/26/04
- Next message: Sherif ElMetainy: "Re: String and StringBuilder sealed ... another WHY"
- Previous message: Stefano Galluzzo: "Work with ZIP files"
- In reply to: Jon Skeet [C# MVP]: "Re: String empty test"
- Next in thread: Jon Skeet [C# MVP]: "Re: String empty test"
- Reply: Jon Skeet [C# MVP]: "Re: String empty test"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 26 Mar 2004 08:54:29 -0000
I seem to recall that the FxCop tool (http://www.gotdotnet.com/team/fxcop/)
notes that the preferred way to test for an empty string is str.Length== 0
(plus all the Trim comments from previous posts of course ;-)
James
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1acdc79c7d80b51d98a4a1@msnews.microsoft.com...
> William Stacey [MVP] <staceywREMOVE@mvps.org> wrote:
> > As an FYI, Empty is actually a public static string var set to Empty =
"" in
> > the string classes static constructor. This should probably be faster
then
> > testing Length == 0, but as you said, probably could not tell the
difference
> > until you ran millions of times in a loop.
>
> Why would it be faster? I could see how it could be faster in the cases
> where you ended up with another reference to the same object as
> String.Empty, but otherwise it's got to compare the strings for
> equality somehow - and that's got to compare the lengths anyway.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: Sherif ElMetainy: "Re: String and StringBuilder sealed ... another WHY"
- Previous message: Stefano Galluzzo: "Work with ZIP files"
- In reply to: Jon Skeet [C# MVP]: "Re: String empty test"
- Next in thread: Jon Skeet [C# MVP]: "Re: String empty test"
- Reply: Jon Skeet [C# MVP]: "Re: String empty test"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|