当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET SortedList.GetByIndex方法代码示例

本文整理汇总了VB.NET中System.Collections.SortedList.GetByIndex方法的典型用法代码示例。如果您正苦于以下问题:VB.NET SortedList.GetByIndex方法的具体用法?VB.NET SortedList.GetByIndex怎么用?VB.NET SortedList.GetByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.SortedList的用法示例。


在下文中一共展示了SortedList.GetByIndex方法的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.GetByIndex

输出:

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.GetByIndex


注:本文中的System.Collections.SortedList.GetByIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。