本文整理汇总了VB.NET中System.Collections.Generic.SortedList<TKey,TValue>.SortedList构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET SortedList<TKey,TValue>构造函数的具体用法?VB.NET SortedList<TKey,TValue>怎么用?VB.NET SortedList<TKey,TValue>使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在类System.Collections.Generic.SortedList<TKey,TValue>
的用法示例。
在下文中一共展示了SortedList<TKey,TValue>构造函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: SortedList
' Create a new sorted list of strings, with string
' keys.
Dim openWith As New SortedList(Of String, String)
' Add some elements to the list. There are no
' duplicate keys, but some of the values are duplicates.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("dib", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' The Add method throws an exception if the new key is
' already in the list.
Try
openWith.Add("txt", "winword.exe")
Catch
Console.WriteLine("An element with Key = ""txt"" already exists.")
End Try
示例2: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create a new sorted list of strings, with string keys and
' a case-insensitive comparer for the current culture.
Dim openWith As New SortedList(Of String, String)( _
StringComparer.CurrentCultureIgnoreCase)
' Add some elements to the list.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("DIB", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' Try to add a fifth element with a key that is the same
' except for case; this would be allowed with the default
' comparer.
Try
openWith.Add("BMP", "paint.exe")
Catch ex As ArgumentException
Console.WriteLine(vbLf & "BMP is already in the sorted list.")
End Try
' List the contents of the sorted list.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
End Sub
End Class
输出:
BMP is already in the sorted list. Key = bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe
示例3: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create a new Dictionary of strings, with string
' keys.
Dim openWith As New Dictionary(Of String, String)
' Add some elements to the dictionary.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("dib", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' Create a SortedList of strings with string keys,
' and initialize it with the contents of the Dictionary.
Dim copy As New SortedList(Of String, String)(openWith)
' List the sorted contents of the copy.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In copy
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
End Sub
End Class
输出:
Key = bmp, Value = paint.exe Key = dib, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe
示例4: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create a new sorted list of strings, with string keys and
' an initial capacity of 4.
Dim openWith As New SortedList(Of String, String)(4)
' Add 4 elements to the list.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("dib", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' List the contents of the sorted list.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
End Sub
End Class
输出:
Key = bmp, Value = paint.exe Key = dib, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe
示例5: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create a new Dictionary of strings, with string keys and
' a case-insensitive equality comparer for the current
' culture.
Dim openWith As New Dictionary(Of String, String)( _
StringComparer.CurrentCultureIgnoreCase)
' Add some elements to the dictionary.
openWith.Add("txt", "notepad.exe")
openWith.Add("Bmp", "paint.exe")
openWith.Add("DIB", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' Create a SortedList of strings with string keys and a
' case-insensitive equality comparer for the current culture,
' and initialize it with the contents of the Dictionary.
Dim copy As New SortedList(Of String, String)(openWith, _
StringComparer.CurrentCultureIgnoreCase)
' List the sorted contents of the copy.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In copy
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
End Sub
End Class
输出:
Key = Bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe
示例6: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
' Create a new sorted list of strings, with string keys, an
' initial capacity of 5, and a case-insensitive comparer.
Dim openWith As New SortedList(Of String, String)(5, _
StringComparer.CurrentCultureIgnoreCase)
' Add 4 elements to the list.
openWith.Add("txt", "notepad.exe")
openWith.Add("bmp", "paint.exe")
openWith.Add("DIB", "paint.exe")
openWith.Add("rtf", "wordpad.exe")
' Try to add a fifth element with a key that is the same
' except for case; this would be allowed with the default
' comparer.
Try
openWith.Add("BMP", "paint.exe")
Catch ex As ArgumentException
Console.WriteLine(vbLf & "BMP is already in the sorted list.")
End Try
' List the contents of the sorted list.
Console.WriteLine()
For Each kvp As KeyValuePair(Of String, String) In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
kvp.Key, kvp.Value)
Next kvp
End Sub
End Class
输出:
BMP is already in the sorted list. Key = bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe