When comparing two strings in c# for equality, what is the difference between InvariantCulture and Ordinal comparison?
When comparing two strings in c# for equality, what is the difference between InvariantCulture
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
InvariantCulture
Uses a "standard" set of character orderings (a,b,c, … etc.). This is in contrast to some specific locales, which may sort characters in different orders (‘a-with-acute’ may be before or after ‘a’, depending on the locale, and so on).
Ordinal
On the other hand, looks purely at the values of the raw byte(s) that represent the character.
There’s a great sample at https://learn.microsoft.com/en-us/dotnet/api/system.string.compare that shows the results of the various StringComparison values. All the way at the end, it shows (excerpted):
You can see that where InvariantCulture yields (U+0069, U+0049, U+00131), Ordinal yields (U+0049, U+0069, U+00131).