Mega Code Archive

 
Categories / VB.Net / Data Structure
 

The Add method throws an exception if the new key is already in the dictionary

Imports System Imports System.Collections.Generic Public Class Example     Public Shared Sub Main()          Dim openWith As New SortedDictionary(Of String, String)         openWith.Add("A", "a")         openWith.Add("B", "b")         openWith.Add("C", "c")         openWith.Add("D", "d")         Try             openWith.Add("txt", "winword.exe")         Catch              Console.WriteLine("An element with Key = ""txt"" already exists.")         End Try     End Sub End Class