how was Array.Sort implemented in .NET?

后端 未结 6 560
遇见更好的自我
遇见更好的自我 2021-01-13 21:28

I am using structures in my programming and I sort the structure according to a value in the structure using IComparer.

How did Microsoft implement th

6条回答
  •  Happy的楠姐
    2021-01-13 22:12

    First of all, let's address several issues in your current plan with regards to best practices for .Net (VB or C#):

    1. Prefer Class over Structure unless you have a good reason to do otherwise
    2. Avoid using Arrays
    3. You can build that array as a one-liner: Dim MyArray() As Integer = {1, 45, 45, 1, 10, 1, 57}

    As to your question of whether it's the "same" value 1, the answer is that it depends on how you look at it. For the general case, the answer is whether or not the sorting algorithm is considered stable. .Net's sorting algorithm in not stable.

    For this specific case, you're asking the wrong question. 1 is 1 is 1. There is no distinction between them. If you feel like it matters, I challenge you to provide code to detect a difference between any two of the "1s" from that list in your original code (aside from array index).

提交回复
热议问题