开发者

Sorting numbers in descending order

I have 20 t开发者_StackOverflowextboxes. each contains a particular number . I want the textbox1 to textboxN to have the numbers in the descending order. If any of the textbox has a zero value then I want to leave that textbox as it is. A sample code in vb.net needed.


'for sorting the elements in descending order

   dim array(4) as integer 
     array(4)={4,6,2,9,1}
       'first sort the array and then reverse it as
      array.sort(4)
      array.reverse(4)
     sortlistbox.item.add(array(4))


  Dim txt As New List(Of TextBox)
    Dim q = From i In txt 
            Where CInt(i.Attributes("value")) > 0 
            Order By CInt(i.Attributes("value")) Descending 
            Select i

Whana try some simple linq query over your collection?


This one is a bit old, but I ran into the same problem.

Using MSDN I found this: Enumerable.OrderBy Method (IEnumerable, Func)

If you just add .Reverse to that query, it's descending:

Dim query As IEnumerable(Of Pet) = pets.OrderBy(Function(pet) pet.Age).Reverse


@Thom Morgan

This one is a bit old, but I ran into the same problem. Using MSDN I found this: Enumerable.OrderBy Method (IEnumerable, Func) If you just add .Reverse to that query, it's descending:

Dim query As IEnumerable(Of Pet) = pets.OrderBy(Function(pet) pet.Age).Reverse

This worked like a charm! Thank you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜