當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET SortedList.GetKey方法代碼示例

本文整理匯總了VB.NET中System.Collections.SortedList.GetKey方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET SortedList.GetKey方法的具體用法?VB.NET SortedList.GetKey怎麽用?VB.NET SortedList.GetKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Collections.SortedList的用法示例。


在下文中一共展示了SortedList.GetKey方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: SamplesSortedList

' 導入命名空間
Imports System.Collections

Public Class SamplesSortedList
        
    Public Shared Sub Main()
        
        ' Creates and initializes a new SortedList.
        Dim mySL As New SortedList()
        mySL.Add(1.3, "fox")
        mySL.Add(1.4, "jumps")
        mySL.Add(1.5, "over")
        mySL.Add(1.2, "brown")
        mySL.Add(1.1, "quick")
        mySL.Add(1.0, "The")
        mySL.Add(1.6, "the")
        mySL.Add(1.8, "dog")
        mySL.Add(1.7, "lazy")
        
        ' Gets the key and the value based on the index.
        Dim myIndex As Integer = 3
        Console.WriteLine("The key   at index {0} is {1}.", myIndex, _
           mySL.GetKey(myIndex))
        Console.WriteLine("The value at index {0} is {1}.", myIndex, _
           mySL.GetByIndex(myIndex))
        
        ' Gets the list of keys and the list of values.
        Dim myKeyList As IList = mySL.GetKeyList()
        Dim myValueList As IList = mySL.GetValueList()
        
        ' Prints the keys in the first column and the values in the second column.
        Console.WriteLine(ControlChars.Tab & "-KEY-" & ControlChars.Tab & _
           "-VALUE-")
        Dim i As Integer
        For i = 0 To mySL.Count - 1
            Console.WriteLine(ControlChars.Tab & "{0}" & ControlChars.Tab & _
               "{1}", myKeyList(i), myValueList(i))
        Next i
    End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System.Collections,代碼行數:40,代碼來源:SortedList.GetKey

輸出:

The key   at index 3 is 1.3.
The value at index 3 is fox.
-KEY-    -VALUE-
1    The
1.1    quick
1.2    brown
1.3    fox
1.4    jumps
1.5    over
1.6    the
1.7    lazy
1.8    dog

示例2: MainClass

' 導入命名空間
Imports System
Imports System.Collections
Imports System.Collections.Specialized


Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim sortedList As New SortedList
        sortedList.Add("2", "T")
        sortedList.Add("0", "T")
        sortedList.Add("1", "O")
        sortedList.Add("6", "S")

        For i As Integer = 0 To sortedList.Count - 1
            Console.WriteLine(sortedList.GetKey(i).ToString() & ": " & _
                sortedList.GetByIndex(i).ToString())
        Next i

        sortedList.Clear()
    End Sub
End Class
開發者ID:VB程序員,項目名稱:System.Collections,代碼行數:23,代碼來源:SortedList.GetKey


注:本文中的System.Collections.SortedList.GetKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。