devxlogo

The Right Way to Do Insensitive String Comparison

The Right Way to Do Insensitive String Comparison

We often do String.ToUpper()?on two strings to compare them. This introduces additional overhead on string allocation. It is better to use OrdinalIgnoreCase?instead, as shown below:

bool CompareResult = firstString.Equals(secondString, StringComparison.OrdinalIgnoreCase);

devx-admin

Share the Post: