You can use string.Compare (x, y) instead of < , which returns 0 if the string is equal, otherwise an integer indicating their relative position in sort order
for (int index = 0; index < (letters.Length - 1); index++) { if (string.Compare (letters[index], letters[index + 1]) < 0) //if first number is greater then second then swap { //swap temp = letters[index]; letters[index] = letters[index + 1]; letters[index + 1] = temp; swap = true; } }
If you want to ignore the case during the comparison, you should use string.Compare (letters[index], letters[index + 1], true)
source share