In the String Performance chapter of my code performance book, I demonstrated how to use Compare()
, but it’s essential to always use it with a StringComparison
, as shown below.
bool result = string.Compare(email1, email2,
StringComparison.CurrentCultureIgnoreCase)
Benchmark Results
Here are the benchmark results for your reference.
Depending on the strings being compared, I recommend using either one of the cultures or one of the ordinals.
When I setup my EditorConfig it looks like this:
dotnet_diagnostic.CA1862.severity = warning
Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyIf you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave
© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.