How to sort elements of array list in C#

后端 未结 9 1149
梦如初夏
梦如初夏 2021-02-14 23:42

I have an ArrayList that contains,

[0] = \"1\"
[1] = \"10\"
[2] = \"2\"
[3] = \"15\"
[4] = \"17\"
[5] = \"5\"
[6] = \"6\"
[7] = \"27\"
[8] = \"8\"
[9] = \"9\"
         


        
9条回答
  •  Happy的楠姐
    2021-02-15 00:09

    You'll be better of creating another array with Int values and then sorting it with ArrayList.Sort(). You could call ArrayList.Sort() and pass it a delegate that will compare those strings as numbers but it will be slower. How much slower depends on size of your array and I personally think for sizes less then 100 it doesn't really matter.

提交回复
热议问题