Re: String empty test

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

From: James Hebben (james.hebben_at_extraview.co.uk_nospam)
Date: 03/26/04


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



Relevant Pages

  • Re: 32-bit programs on Windows x64
    ... tiny individual sequences. ... to compare its input string against every possible ... compare one string against one string, ...
    (microsoft.public.vc.mfc)
  • Re: 32-bit programs on Windows x64
    ... THE AMOUNT OF RAM ON THE MACHINE IS COMPLETELY, ... nothing in that article that implies any concurrency. ... to compare its input string against every possible valid ...
    (microsoft.public.vc.mfc)
  • Re: 32-bit programs on Windows x64
    ... THE AMOUNT OF RAM ON THE MACHINE IS COMPLETELY, ... nothing in that article that implies any concurrency. ... to compare its input string against every possible valid ...
    (microsoft.public.vc.mfc)
  • Re: 32-bit programs on Windows x64
    ... machine has "parallelism" ... to compare its input string against every possible valid ...
    (microsoft.public.vc.mfc)
  • Re: 32-bit programs on Windows x64
    ... THE AMOUNT OF RAM ON THE MACHINE IS COMPLETELY, ... to compare its input string against every possible valid ... Note that the L2 cache is ...
    (microsoft.public.vc.mfc)