Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Performing Culture-Insensitive String Operations in Arrays

Overloads of the Array.Sort and Array.BinarySearch methods perform culture-sensitive sorts by default using the Thread.CurrentCulture property. Culture-sensitive results returned by these methods can vary by culture due to differences in sort orders. To eliminate culture-sensitive behavior, use one of the overloads of this method that accepts a comparer parameter. The comparer parameter specifies the IComparer implementation to use when comparing elements in the array. For the parameter, specify a custom invariant comparer class that uses CultureInfo.InvariantCulture. An example of a custom invariant comparer class is provided in the "Using the SortedList Class" subtopic of the Performing Culture-Insensitive String Operations in Collections topic.

Note   Passing CultureInfo.InvariantCulture to a comparison method does perform a culture-insensitive comparison. However, it does not cause a non-linguistic comparison, for example, for file paths, registry keys, and environment variables. Neither does it support security decisions based on the comparison result. For a non-linguistic comparison or support for result-based security decisions, the application should use a comparison method that accepts a StringComparison value. The application should then pass Ordinal.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.