Freigeben über


SayIt, don't spray it! [Free program (and source code) makes it easy to use text-to-speech from your own programs and scripts]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

Comments

  • Anonymous
    January 06, 2011
    Nice! Is there a reason you're using "0 == string.Compare(...)" instead of "string.Equals(...)"?

  • Anonymous
    January 06, 2011
    RichardDeeming, I usually go with string.Compare for its culture-correctness and flexibility. In this case I think I'm only ever doing ordinal comparisons and string.Equals would work the same, but I still like being consistent. :) Here's a blog post that has some great information on the topic: blogs.msdn.com/.../string-compare-string-equals-josh-free.aspx

  • Anonymous
    January 06, 2011
    That was correct for .NET 1, but .NET 2 added overloads of the static and instance Equals methods which accept a StringComparison parameter for precisely this reason: msdn.microsoft.com/.../t4411bks%28v=VS.80%29.aspx msdn.microsoft.com/.../ms973919.aspx

  • Anonymous
    January 06, 2011
    RichardDeeming, Fair point - the two methods seem to be a lot more similar now than they originally were - and I agree either could have worked for my scenario. To be fair, Compare has more overloads (mainly to support passing a CultureInfo) and returns a value indicating the relative sort order, so it seems to remain the more capable of the two. That said, for my general purposes Equals may be more clear and I'll definitely consider using it next time this comes up. :) Thanks for the information!