Skip to content

Commit 0f1d1a6

Browse files
Copilotgewarren
andcommitted
Fix IDictionary`2.xml snippet references to point to new VB snippet locations
Co-authored-by: gewarren <[email protected]>
1 parent e09fea2 commit 0f1d1a6

File tree

2 files changed

+145
-16
lines changed
  • snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview
  • xml/System.Collections.Generic

2 files changed

+145
-16
lines changed
Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,135 @@
1-
Imports System.Collections.Generic
1+
'<Snippet1>
2+
Imports System.Collections.Generic
23

34
Public Class Example
5+
6+
Public Shared Sub Main()
7+
8+
'<Snippet2>
9+
' Create a new dictionary of strings, with string keys,
10+
' and access it through the IDictionary generic interface.
11+
'
12+
Dim openWith As IDictionary(Of String, String) = _
13+
New Dictionary(Of String, String)
14+
15+
' Add some elements to the dictionary. There are no
16+
' duplicate keys, but some of the values are duplicates.
17+
openWith.Add("txt", "notepad.exe")
18+
openWith.Add("bmp", "paint.exe")
19+
openWith.Add("dib", "paint.exe")
20+
openWith.Add("rtf", "wordpad.exe")
21+
22+
' The Add method throws an exception if the new key is
23+
' already in the dictionary.
24+
Try
25+
openWith.Add("txt", "winword.exe")
26+
Catch
27+
Console.WriteLine("An element with Key = ""txt"" already exists.")
28+
End Try
29+
'</Snippet2>
30+
31+
'<Snippet3>
32+
' The Item property is the default property, so you
33+
' can omit its name when accessing elements.
34+
Console.WriteLine("For key = ""rtf"", value = {0}.", _
35+
openWith("rtf"))
36+
37+
' The default Item property can be used to change the value
38+
' associated with a key.
39+
openWith("rtf") = "winword.exe"
40+
Console.WriteLine("For key = ""rtf"", value = {0}.", _
41+
openWith("rtf"))
42+
43+
' If a key does not exist, setting the default Item property
44+
' for that key adds a new key/value pair.
45+
openWith("doc") = "winword.exe"
46+
'</Snippet3>
47+
48+
'<Snippet4>
49+
' The default Item property throws a KeyNotFoundException
50+
' if the requested key is not in the dictionary.
51+
Try
52+
Console.WriteLine("For key = ""tif"", value = {0}.", _
53+
openWith("tif"))
54+
Catch
55+
Console.WriteLine("Key = ""tif"" is not found.")
56+
End Try
57+
'</Snippet4>
58+
59+
'<Snippet5>
60+
' When a program often has to try keys that turn out not to
61+
' be in the dictionary, TryGetValue can be a more efficient
62+
' way to retrieve values.
63+
Dim value As String = ""
64+
If openWith.TryGetValue("tif", value) Then
65+
Console.WriteLine("For key = ""tif"", value = {0}.", value)
66+
Else
67+
Console.WriteLine("Key = ""tif"" is not found.")
68+
End If
69+
'</Snippet5>
70+
71+
'<Snippet6>
72+
' ContainsKey can be used to test keys before inserting
73+
' them.
74+
If Not openWith.ContainsKey("ht") Then
75+
openWith.Add("ht", "hypertrm.exe")
76+
Console.WriteLine("Value added for key = ""ht"": {0}", _
77+
openWith("ht"))
78+
End If
79+
'</Snippet6>
80+
81+
'<Snippet7>
82+
' When you use foreach to enumerate dictionary elements,
83+
' the elements are retrieved as KeyValuePair objects.
84+
Console.WriteLine()
85+
For Each kvp As KeyValuePair(Of String, String) In openWith
86+
Console.WriteLine("Key = {0}, Value = {1}", _
87+
kvp.Key, kvp.Value)
88+
Next
89+
'</Snippet7>
90+
91+
'<Snippet8>
92+
' To get the values alone, use the Values property.
93+
Dim ivals As ICollection(Of String) = openWith.Values
94+
95+
' The elements of the ICollection(Of String) are strongly typed
96+
' with the type that was specified for dictionary values.
97+
Console.WriteLine()
98+
For Each s As String In ivals
99+
Console.WriteLine("Value = {0}", s)
100+
Next s
101+
'</Snippet8>
102+
103+
'<Snippet9>
104+
' To get the keys alone, use the Keys property.
105+
Dim ikeys As ICollection(Of String) = openWith.Keys
106+
107+
' The elements of the ICollection(Of String) are strongly typed
108+
' with the type that was specified for dictionary keys.
109+
Console.WriteLine()
110+
For Each s As String In ikeys
111+
Console.WriteLine("Key = {0}", s)
112+
Next s
113+
'</Snippet9>
114+
115+
'<Snippet10>
116+
' Use the Remove method to remove a key/value pair.
117+
Console.WriteLine(vbLf + "Remove(""dib"")")
118+
openWith.Remove("dib")
119+
120+
If Not openWith.ContainsKey("dib") Then
121+
Console.WriteLine("Key ""dib"" is not found.")
122+
End If
123+
'</Snippet10>
124+
125+
End Sub
126+
127+
End Class
128+
129+
' Example for Snippet11 - separate from main example
130+
Public Class Snippet11Example
4131
Public Shared Sub Main()
5-
' Create a new dictionary of strings, with string keys.
132+
' Create a new dictionary of strings, with integer keys.
6133
'
7134
Dim exDictionary As New Dictionary(Of Integer, String)
8135

@@ -13,11 +140,13 @@ Public Class Example
13140
exDictionary.Add(2, "paint.exe")
14141
exDictionary.Add(3, "wordpad.exe")
15142
Dim myDictionary As IDictionary(Of Integer, String) = exDictionary
143+
16144
' <Snippet11>
17145
For Each kvp As KeyValuePair(Of Integer, String) In myDictionary
18146
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value)
19147
Next kvp
20148
' </Snippet11>
149+
21150
End Sub
22151
End Class
23-
152+
'</Snippet1>

xml/System.Collections.Generic/IDictionary`2.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
Finally, the example shows how to enumerate the keys and values in the dictionary, and how to enumerate the values alone using the <xref:System.Collections.Generic.IDictionary%602.Values%2A> property.
114114
115115
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" interactive="try-dotnet" id="Snippet1":::
116-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet1":::
116+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet1":::
117117
118118
]]></format>
119119
</remarks>
@@ -188,7 +188,7 @@
188188
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
189189
190190
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" interactive="try-dotnet-method" id="Snippet2":::
191-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet2":::
191+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet2":::
192192
193193
]]></format>
194194
</remarks>
@@ -260,11 +260,11 @@
260260
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
261261
262262
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet6":::
263-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet6":::
263+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet6":::
264264
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet5":::
265-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet5":::
265+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet5":::
266266
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet4":::
267-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet4":::
267+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet4":::
268268
269269
]]></format>
270270
</remarks>
@@ -341,11 +341,11 @@
341341
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
342342
343343
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet3":::
344-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet3":::
344+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet3":::
345345
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet4":::
346-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet4":::
346+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet4":::
347347
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet5":::
348-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet5":::
348+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet5":::
349349
350350
]]></format>
351351
</remarks>
@@ -413,7 +413,7 @@
413413
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
414414
415415
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet9":::
416-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet9":::
416+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet9":::
417417
418418
]]></format>
419419
</remarks>
@@ -480,7 +480,7 @@
480480
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
481481
482482
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet10":::
483-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet10":::
483+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet10":::
484484
485485
]]></format>
486486
</remarks>
@@ -561,9 +561,9 @@
561561
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
562562
563563
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet5":::
564-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet5":::
564+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet5":::
565565
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet4":::
566-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet4":::
566+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet4":::
567567
568568
]]></format>
569569
</remarks>
@@ -628,7 +628,7 @@
628628
This code is part of a larger example that can be compiled and executed. See <xref:System.Collections.Generic.IDictionary%602?displayProperty=nameWithType>.
629629
630630
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.cs" id="Snippet8":::
631-
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Generic.IDictionary/VB/source.vb" id="Snippet8":::
631+
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/IDictionaryTKey,TValue/Overview/source.vb" id="Snippet8":::
632632
633633
]]></format>
634634
</remarks>

0 commit comments

Comments
 (0)