Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions xml/System.Collections.Generic/Dictionary`2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)]

The following code example creates an empty <xref:System.Collections.Generic.Dictionary%602> of strings with string keys and uses the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method to add some elements. The example demonstrates that the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method throws an <xref:System.ArgumentException> when attempting to add a duplicate key.

The example uses the <xref:System.Collections.Generic.Dictionary%602.Item%2A> property (the indexer in C#) to retrieve values, demonstrating that a <xref:System.Collections.Generic.KeyNotFoundException> is thrown when a requested key is not present, and showing that the value associated with a key can be replaced.
Expand All @@ -130,7 +133,7 @@
Finally, the example demonstrates the <xref:System.Collections.Generic.Dictionary%602.Remove%2A> method.

[!code-cpp[Generic.Dictionary#1](~/samples/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp#1)]
[!code-csharp[Generic.Dictionary#1](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#1)]
[!code-csharp-interactive[Generic.Dictionary#1](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#1)]
[!code-vb[Generic.Dictionary#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb#1)]

]]></format>
Expand Down Expand Up @@ -201,12 +204,15 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following code example creates an empty <xref:System.Collections.Generic.Dictionary%602> of strings with string keys and uses the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method to add some elements. The example demonstrates that the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method throws an <xref:System.ArgumentException> when attempting to add a duplicate key.

This code example is part of a larger example provided for the <xref:System.Collections.Generic.Dictionary%602> class.

[!code-cpp[Generic.Dictionary#2](~/samples/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp#2)]
[!code-csharp[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-csharp-interactive[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-vb[Generic.Dictionary#2](~/samples/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb#2)]

]]></format>
Expand Down Expand Up @@ -702,12 +708,15 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)]

The following code example creates an empty <xref:System.Collections.Generic.Dictionary%602> of strings with string keys and uses the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method to add some elements. The example demonstrates that the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method throws an <xref:System.ArgumentException> when attempting to add a duplicate key.

This code example is part of a larger example provided for the <xref:System.Collections.Generic.Dictionary%602> class.

[!code-cpp[Generic.Dictionary#2](~/samples/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp#2)]
[!code-csharp[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-csharp-interactive[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-vb[Generic.Dictionary#2](~/samples/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb#2)]

]]></format>
Expand Down Expand Up @@ -1198,14 +1207,17 @@


## Examples

[!INCLUDE[interactive-note](~/includes/csharp-interactive-note-some.md)]

The following code example uses the <xref:System.Collections.Generic.Dictionary%602.Item%2A> property (the indexer in C#) to retrieve values, demonstrating that a <xref:System.Collections.Generic.KeyNotFoundException> is thrown when a requested key is not present, and showing that the value associated with a key can be replaced.

The example also shows how to use the <xref:System.Collections.Generic.Dictionary%602.TryGetValue%2A> method as a more efficient way to retrieve values if a program often must try key values that are not in the dictionary.

This code example is part of a larger example provided for the <xref:System.Collections.Generic.Dictionary%602> class. `openWith` is the name of the Dictionary used in this example.

[!code-cpp[Generic.Dictionary#2](~/samples/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp#2)]
[!code-csharp[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-csharp-interactive[Generic.Dictionary#2](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#2)]
[!code-vb[Generic.Dictionary#2](~/samples/snippets/visualbasic/VS_Snippets_CLR/Generic.Dictionary/VB/source.vb#2)]
[!code-cpp[Generic.Dictionary#3](~/samples/snippets/cpp/VS_Snippets_CLR/Generic.Dictionary/cpp/source.cpp#3)]
[!code-csharp[Generic.Dictionary#3](~/samples/snippets/csharp/VS_Snippets_CLR/Generic.Dictionary/CS/source.cs#3)]
Expand Down Expand Up @@ -2951,4 +2963,4 @@ Unlike the <xref:System.Collections.Generic.Dictionary%602.Add%2A> method, this
</Docs>
</Member>
</Members>
</Type>
</Type>