given an array of strings, and I want to sort it, the code as follows
string[] s = ["=:rr", "2:yy", "=:hh"];
Array.Sort(s);
foreach (var item in s)
{
Console.WriteLine(item);
}
my expected result:
2:yy
=:hh
=:rr
the actually result:
=:hh
=:rr
2:yy
From what I understand, strings are sorted based on the Unicode value of each character. ‘2’ has a Unicode value of 50, and ‘=’ has a Unicode value of 61. So why isn’t the result as expected?
New contributor
Silophon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.