本文整理汇总了VB.NET中System.Collections.SortedList.SortedList构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET SortedList构造函数的具体用法?VB.NET SortedList怎么用?VB.NET SortedList使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.Collections.SortedList 的用法示例。
在下文中一共展示了SortedList构造函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SamplesSortedList
' 导入命名空间
Imports System.Collections
Imports System.Globalization
Public Class SamplesSortedList
Public Shared Sub Main()
' Create a SortedList using the default comparer.
Dim mySL1 As New SortedList()
Console.WriteLine("mySL1 (default):")
mySL1.Add("FIRST", "Hello")
mySL1.Add("SECOND", "World")
mySL1.Add("THIRD", "!")
Try
mySL1.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL1)
' Create a SortedList using the specified case-insensitive comparer.
Dim mySL2 As New SortedList(New CaseInsensitiveComparer())
Console.WriteLine("mySL2 (case-insensitive comparer):")
mySL2.Add("FIRST", "Hello")
mySL2.Add("SECOND", "World")
mySL2.Add("THIRD", "!")
Try
mySL2.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL2)
' Create a SortedList using the specified CaseInsensitiveComparer,
' which is based on the Turkish culture (tr-TR), where "I" is not
' the uppercase version of "i".
Dim myCul As New CultureInfo("tr-TR")
Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul))
Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):")
mySL3.Add("FIRST", "Hello")
mySL3.Add("SECOND", "World")
mySL3.Add("THIRD", "!")
Try
mySL3.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL3)
' Create a SortedList using the
' StringComparer.InvariantCultureIgnoreCase value.
Dim mySL4 As New SortedList( _
StringComparer.InvariantCultureIgnoreCase)
Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):")
mySL4.Add("FIRST", "Hello")
mySL4.Add("SECOND", "World")
mySL4.Add("THIRD", "!")
Try
mySL4.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL4)
End Sub
Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList)
Console.WriteLine(" -KEY- -VALUE-")
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine(" {0,-6}: {1}", _
myList.GetKey(i), myList.GetByIndex(i))
Next i
Console.WriteLine()
End Sub
End Class
'This code produces the following output. Results vary depending on the system's culture settings.
'
'mySL1 (default):
' -KEY- -VALUE-
' first : Ola!
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL2 (case-insensitive comparer):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL3 (case-insensitive comparer, Turkish culture):
' -KEY- -VALUE-
' FIRST : Hello
' first : Ola!
' SECOND: World
' THIRD : !
'
'mySL4 (InvariantCultureIgnoreCase):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
开发者ID:VB.NET开发者,项目名称:System.Collections,代码行数:111,代码来源:SortedList
示例2: SamplesSortedList
' 导入命名空间
Imports System.Collections
Imports System.Globalization
Public Class SamplesSortedList
Public Shared Sub Main()
' Create the dictionary.
Dim myHT As New Hashtable()
myHT.Add("FIRST", "Hello")
myHT.Add("SECOND", "World")
myHT.Add("THIRD", "!")
' Create a SortedList using the default comparer.
Dim mySL1 As New SortedList(myHT)
Console.WriteLine("mySL1 (default):")
Try
mySL1.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL1)
' Create a SortedList using the specified case-insensitive comparer.
Dim mySL2 As New SortedList(myHT, New CaseInsensitiveComparer())
Console.WriteLine("mySL2 (case-insensitive comparer):")
Try
mySL2.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL2)
' Create a SortedList using the specified CaseInsensitiveComparer,
' which is based on the Turkish culture (tr-TR), where "I" is not
' the uppercase version of "i".
Dim myCul As New CultureInfo("tr-TR")
Dim mySL3 As New SortedList(myHT, New CaseInsensitiveComparer(myCul))
Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):")
Try
mySL3.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL3)
' Create a SortedList using the
' StringComparer.InvariantCultureIgnoreCase value.
Dim mySL4 As New SortedList(myHT, StringComparer.InvariantCultureIgnoreCase)
Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):")
Try
mySL4.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL4)
End Sub
Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList)
Console.WriteLine(" -KEY- -VALUE-")
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine(" {0,-6}: {1}", _
myList.GetKey(i), myList.GetByIndex(i))
Next i
Console.WriteLine()
End Sub
End Class
'This code produces the following output. Results vary depending on the system's culture settings.
'
'mySL1 (default):
' -KEY- -VALUE-
' first : Ola!
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL2 (case-insensitive comparer):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL3 (case-insensitive comparer, Turkish culture):
' -KEY- -VALUE-
' FIRST : Hello
' first : Ola!
' SECOND: World
' THIRD : !
'
'mySL4 (InvariantCultureIgnoreCase):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
开发者ID:VB.NET开发者,项目名称:System.Collections,代码行数:104,代码来源:SortedList
示例3: SamplesSortedList
' 导入命名空间
Imports System.Collections
Imports System.Globalization
Public Class SamplesSortedList
Public Shared Sub Main()
' Create a SortedList using the default comparer.
Dim mySL1 As New SortedList( 3 )
Console.WriteLine("mySL1 (default):")
mySL1.Add("FIRST", "Hello")
mySL1.Add("SECOND", "World")
mySL1.Add("THIRD", "!")
Try
mySL1.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL1)
' Create a SortedList using the specified case-insensitive comparer.
Dim mySL2 As New SortedList(New CaseInsensitiveComparer(), 3)
Console.WriteLine("mySL2 (case-insensitive comparer):")
mySL2.Add("FIRST", "Hello")
mySL2.Add("SECOND", "World")
mySL2.Add("THIRD", "!")
Try
mySL2.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL2)
' Create a SortedList using the specified CaseInsensitiveComparer,
' which is based on the Turkish culture (tr-TR), where "I" is not
' the uppercase version of "i".
Dim myCul As New CultureInfo("tr-TR")
Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul), 3)
Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):")
mySL3.Add("FIRST", "Hello")
mySL3.Add("SECOND", "World")
mySL3.Add("THIRD", "!")
Try
mySL3.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL3)
' Create a SortedList using the
' StringComparer.InvariantCultureIgnoreCase value.
Dim mySL4 As New SortedList( _
StringComparer.InvariantCultureIgnoreCase, 3)
Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):")
mySL4.Add("FIRST", "Hello")
mySL4.Add("SECOND", "World")
mySL4.Add("THIRD", "!")
Try
mySL4.Add("first", "Ola!")
Catch e As ArgumentException
Console.WriteLine(e)
End Try
PrintKeysAndValues(mySL4)
End Sub
Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList)
Console.WriteLine(" -KEY- -VALUE-")
Dim i As Integer
For i = 0 To myList.Count - 1
Console.WriteLine(" {0,-6}: {1}", _
myList.GetKey(i), myList.GetByIndex(i))
Next i
Console.WriteLine()
End Sub
End Class
'This code produces the following output. Results vary depending on the system's culture settings.
'
'mySL1 (default):
' -KEY- -VALUE-
' first : Ola!
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL2 (case-insensitive comparer):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
'
'mySL3 (case-insensitive comparer, Turkish culture):
' -KEY- -VALUE-
' FIRST : Hello
' first : Ola!
' SECOND: World
' THIRD : !
'
'mySL4 (InvariantCultureIgnoreCase):
'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value)
' at SamplesSortedList.Main()
' -KEY- -VALUE-
' FIRST : Hello
' SECOND: World
' THIRD : !
开发者ID:VB.NET开发者,项目名称:System.Collections,代码行数:111,代码来源:SortedList
注:本文中的System.Collections.SortedList.SortedList构造函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论