本文整理汇总了VB.NET中System.Linq.Queryable.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Queryable.OrderByDescending方法的具体用法?VB.NET Queryable.OrderByDescending怎么用?VB.NET Queryable.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Queryable.OrderByDescending方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SpecialComparer
''' <summary>
''' This class provides a custom implementation of the
''' IComparer.Compare() method. It sorts by the fractional part of the decimal number.
''' </summary>
Class SpecialComparer
Implements IComparer(Of Decimal)
''' <summary>
''' Compare two decimal numbers by their fractional parts.
''' </summary>
''' <param name="d1">The first decimal to compare.</param>
''' <param name="d2">The second decimal to compare.</param>
''' <returns>1 if the first decimal's fractional part is greater than
''' the second decimal's fractional part,
''' -1 if the first decimal's fractional
''' part is less than the second decimal's fractional part,
''' or the result of calling Decimal.Compare()
''' if the fractional parts are equal.</returns>
Function Compare(ByVal d1 As Decimal, ByVal d2 As Decimal) As Integer _
Implements IComparer(Of Decimal).Compare
Dim fractional1 As Decimal
Dim fractional2 As Decimal
' Get the fractional part of the first number.
Try
fractional1 = Decimal.Remainder(d1, Decimal.Floor(d1))
Catch ex As DivideByZeroException
fractional1 = d1
End Try
' Get the fractional part of the second number.
Try
fractional2 = Decimal.Remainder(d2, Decimal.Floor(d2))
Catch ex As DivideByZeroException
fractional2 = d2
End Try
If (fractional1 = fractional2) Then
' The fractional parts are equal, so compare the entire numbers.
Return Decimal.Compare(d1, d2)
ElseIf (fractional1 > fractional2) Then
Return 1
Else
Return -1
End If
End Function
End Class
Sub OrderByDescendingEx1()
' Create a list of decimal values.
Dim decimals As New List(Of Decimal)(New Decimal() _
{6.2D, 8.3D, 0.5D, 1.3D, 6.3D, 9.7D})
' Order the elements of the list by passing
' in the custom IComparer class.
Dim query As IEnumerable(Of Decimal) = _
decimals.AsQueryable(). _
OrderByDescending(Function(num) num, New SpecialComparer())
Dim output As New System.Text.StringBuilder
For Each num As Decimal In query
output.AppendLine(num)
Next
' Display the output.
MsgBox(output.ToString())
End Sub
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:68,代码来源:Queryable.OrderByDescending 输出:
9.7
0.5
8.3
6.3
1.3
6.2
注:本文中的System.Linq.Queryable.OrderByDescending方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论