本文整理匯總了VB.NET中System.Globalization.SortKey類的典型用法代碼示例。如果您正苦於以下問題:VB.NET SortKey類的具體用法?VB.NET SortKey怎麽用?VB.NET SortKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SortKey類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: SamplesSortKey
' 導入命名空間
Imports System.Globalization
Public Class SamplesSortKey
Public Shared Sub Main()
' Creates a SortKey using the en-US culture.
Dim myComp_enUS As CompareInfo = New CultureInfo("en-US", False).CompareInfo
Dim mySK1 As SortKey = myComp_enUS.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with international sort.
Dim myComp_esES As CompareInfo = New CultureInfo("es-ES", False).CompareInfo
Dim mySK2 As SortKey = myComp_esES.GetSortKey("llama")
' Creates a SortKey using the es-ES culture with traditional sort.
Dim myComp_es As CompareInfo = New CultureInfo(&H40A, False).CompareInfo
Dim mySK3 As SortKey = myComp_es.GetSortKey("llama")
' Compares the en-US SortKey with each of the es-ES SortKey objects.
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with international sort : {0}", SortKey.Compare(mySK1, mySK2))
Console.WriteLine("Comparing ""llama"" in en-US and in es-ES with traditional sort : {0}", SortKey.Compare(mySK1, mySK3))
End Sub
End Class
輸出:
Comparing "llama" in en-US and in es-ES with international sort : 0 Comparing "llama" in en-US and in es-ES with traditional sort : -1
示例2: Example
' 導入命名空間
Imports System.Globalization
Module Example
Public Sub Main()
' Define names.
Dim names() As String = { "Adam", "Ignatius", "Batholomew",
"Gregory", "Clement", "Frances",
"Harold", "Dalmatius", "Edgar",
"John", "Benedict", "Paul", "George" }
Dim sortKeys(names.Length - 1) As SortKey
Dim ci As CompareInfo = CultureInfo.CurrentCulture.CompareInfo
For ctr As Integer = 0 To names.Length - 1
sortKeys(ctr) = ci.GetSortKey(names(ctr), CompareOptions.IgnoreCase)
Next
' Sort array based on value of sort keys.
Array.Sort(names, sortKeys)
Console.WriteLine("Sorted array: ")
For Each name In names
Console.WriteLine(name)
Next
Console.WriteLine()
Dim namesToFind() As String = { "Paul", "PAUL", "Wilberforce" }
Console.WriteLine("Searching an array:")
For Each nameToFind In namesToFind
Dim searchKey As SortKey = ci.GetSortKey(nameToFind, CompareOptions.IgnoreCase)
Dim index As Integer = Array.FindIndex(sortKeys,
Function(x) x.Equals(searchKey))
If index >= 0 Then
Console.WriteLine("{0} found at index {1}: {2}", nameToFind,
index, names(index))
Else
Console.WriteLine("{0} not found", nameToFind)
End If
Next
End Sub
End Module
輸出:
Sorted array: Adam Batholomew Benedict Clement Dalmatius Edgar Frances George Gregory Harold Ignatius John Paul Searching an array: Paul found at index 12: Paul PAUL found at index 12: Paul Wilberforce not found