In .NET, when should you use Ordinal(IgnoreCase)
vs InvariantCulture(IgnoreCase)
?
Ordinal(IgnoreCase)
does simple byte comparisions, similar to memcmp, and is faster.
InvariantCulture(IgnoreCase)
applies extra linguistic rules that are English-biased, but not guaranteed to exactly match any "real" culture.
Use Ordinal(IgnoreCase)
when strings are mostly non-linguistic or opaque, e.g. file names, serial numbers.
- Note that most filesystems behave closer to
Ordinal(IgnoreCase)
, whereas UIs like File Explorer may re-sort filenames culture-sensitively.
Use InvariantCulture(IgnoreCase)
when: