Compare returns an integer that indicates their relative position in the sort order, as mentioned at http://msdn.microsoft.com/en-us/library/84787k22.aspx
It tells you the alphabetical ordering of two strings. Here are some test cases that you can try:
code: | String.Compare("A", "B") | Returns -1 since A is alphabetically before B
code: | String.Compare("a", "B") | Returns -1 since a is alphabetically before B
code: | String.Compare("B", "A") | Returns 1 since B is alphabetically after A
code: | String.Compare("B", "B") | Returns 0 since B is alphabetically the same as B
Here?s where it can get confusing:
code: | String.Compare("B", "b") | Returns 1 since although B is alphabetically the same as b, B?s character code is less than b
code: | String.Compare("b", "B") | Returns -1 since although b is alphabetically the same as B, b?s character code is greater than B
The API seems to differ once you start comparing the same letter, but different case. If your intent is to determine that b is alphabetically the same as B, then your best bet is to use this method:
code: | String.Compare("b", "B", true) | Returns 0 - equivalent ignoring case
Where true means to ignore case.
The same thing applies when comparing longer strings, i.e.:
code: | String.Compare("Apple", "Apricot", true) | Returns -1 since apple is alphabetically before Apricot
code: | String.Compare("Apricot", "Apple", true) | Returns 1 since apricot is alphabetically before apple |