vb.net 按降序排列数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4878324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sorting numbers in descending order
提问by SpongeBob SquarePants
I have 20 textboxes. 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.
我有 20 个文本框。每个都包含一个特定的数字。我希望 textbox1 到 textboxN 的数字按降序排列。如果任何文本框的值为零,那么我想保留该文本框原样。需要 vb.net 中的示例代码。
回答by kalim ullah
'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))
回答by Luke
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?
想对您的收藏尝试一些简单的 linq 查询吗?
回答by Luke
This one is a bit old, but I ran into the same problem.
这个有点旧,但我遇到了同样的问题。
Using MSDN I found this: Enumerable.OrderBy Method (IEnumerable, Func)
使用 MSDN 我发现了这个:Enumerable.OrderBy Method (IEnumerable, Func)
If you just add .Reverse
to that query, it's descending:
如果你只是添加.Reverse
到该查询,它是降序的:
Dim query As IEnumerable(Of Pet) = pets.OrderBy(Function(pet) pet.Age).Reverse
回答by delta2echo
@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:
这个有点旧,但我遇到了同样的问题。使用 MSDN 我发现这个: Enumerable.OrderBy Method (IEnumerable, Func) 如果你只是添加 .Reverse 到那个查询,它是降序的:
Dim query As IEnumerable(Of Pet) = pets.OrderBy(Function(pet) pet.Age).Reverse
This worked like a charm! Thank you!
这就像一个魅力!谢谢!