Saturday 3 July, 2010

What is diffrenece between string.compare and string.compareordinal

String.Compare can be or not be case-sensitive, and can incorporate anynumber of comparison options, including culture-sensitivity and sortingrules. That is, it is not comparing the exact strings necessarily, but canbe configured to do various sorts of comparisons. String.CompareOrdinalcompares the numeric values of the individual Unicode characters of thestrings. In other words, it is always case-sensitive, and neverculture-sensitive.

String.CompareOrdinal is faster (more efficient) when you don't need to do aculture-sensitive comparison, and you do want to do a case-sensitivecomparison.String.CompareTo is case-sensitive, using an Ordinal comparison, andculture-sensitive, but always uses the current culture. It is faster thanString.Compare, but less efficient than String.CompareOrdinal.

1 comment: