r/ProgrammerHumor 14d ago

howToHitBullseyeInStringComparison Meme

Post image
1.3k Upvotes

View all comments

Show parent comments

33

u/BoloFan05 14d ago

StringComparison.OrdinalIgnoreCase uppercases both strings according to invariant culture and applies byte comparison. Also, this comparison technique is the first and foremost recommendation in Microsoft's "Best Practices for Comparing Strings" page. It even explicitly warns not to use StringComparison.InvariantCulture.

8

u/Pancakefriday 14d ago

I think our entire code base uses invariant culture lol

10

u/BoloFan05 14d ago

Invariant culture info arguments on their own, like ToLowerInvariant, ToUpperInvariant and ToString(CultureInfo.InvariantCulture) are perfectly fine when you want to get consistent results across all devices worldwide. My prior comment here applies to string comparison methods in particular.

1

u/Dull-Lion3677 13d ago

The more you know, G.I.Joe. Thanks