In C#, it is well known that ".".CompareTo("A") == -1 .
My question is: is there a punctuation mark x such that x.CompareTo("A") == 1 (strangely I can’t find the answer anywhere)
or in other terms, what is the complete default order for strings in C# ?
I know I can define Comparers and Comparisons, but I am asking this question because I am using a class that I cannot modify and that performs a default alphabetical sort on a List of strings.
My problem is that I need to put some dummy values at the end of the list and I would rather have something like:
"value 1"
"value 2"
"_"
"_"
"_"
than
"value 1"
"value 2"
"zzz"
"zzz"
"zzz"
EDIT:
This is not great but I will use (char)738
You should simply use character with code you like (i.e. character
'\uffcc'or string"\uffcc") as sentinel as long as you don’t need to make it printable.Character comparison uses Unicode (UTF-16) character codes. So look at Unicode table to find some like:
‘A’ < ‘{‘ or ‘A’ < ‘¡’.
String comparison: there are no “<” and “>” operators in String class. You need to use Compare method. Usually you use StringComparer class to pick what type of comparison you want case sensitive, culture aware or just by Unicode values.
Unicode type of characters impact default comparison used by CompareTo (when not using compare ordinal). Character with category “OtherLetter” is greater than character with category “OtherSymbol” or “OtherPunctuation” (Char.GetUnicodeCategory). See CompareOptions.StringSort for details.