Comparing two strings, ignoring case in C# [duplicate]

If you’re looking for efficiency, use this:

string.Equals(val, "astringvalue", StringComparison.OrdinalIgnoreCase)

Ordinal comparisons can be significantly faster than culture-aware comparisons.

ToLowerCase can be the better option if you’re doing a lot of comparisons against the same string, however.

As with any performance optimization: measure it, then decide!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)