I am a novice programmer, what do I need to do to avoid mistakes?

Operand> cannot be applied to type string and string

for (int write = 0; write < arr.Length; write++) { for (int sort = 0; sort < arr.Length - 1; sort++) { if (arr[sort] > arr[sort + 1]) { temp = arr[sort + 1]; arr[sort + 1] = arr[sort]; arr[sort] = temp; 
  • do not compare strings. as I understand it - you have an array of strings, right? - Sasha Borichevsky
  • And what do you mean by arr[sort] > arr[sort + 1] ? Do you compare strings? or string length? - Tivyram

1 answer 1

 if (arr[sort] > arr[sort + 1]) 
 if (String.CompareOrdinal(arr[sort], arr[sort + 1]) > 0) 
  • When sorting, it gives me the wrong result, which I want. I use BubbleSort - Andrew Korpach
  • 2
    So use what gives the result that you want. - Qwertiy