Mega Code Archive

 
Categories / VB.Net / Data Structure
 

ContainsKey can be used to test keys before inserting them

Imports System Imports System.Collections.Generic Public Class Example     Public Shared Sub Main()         Dim openWith As New SortedList(Of String, String)         openWith.Add("A", "a")         openWith.Add("B", "b")         openWith.Add("C", "c")         openWith.Add("D", "d")         If Not openWith.ContainsKey("ht") Then             openWith.Add("ht", "hypertrm.exe")             Console.WriteLine("Value added for key = ""ht"": {0}", _                 openWith("ht"))         End If     End Sub End Class