Skip to content

Commit d912043

Browse files
authored
Edit pass and freshness check (#44869)
Edit for accuracy and grammar / style.
1 parent 8930b91 commit d912043

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "How to initialize a dictionary with a collection initializer"
33
description: Learn how to initialize a dictionary in C#, using either the Add method or an index initializer. This example shows both options.
4-
ms.date: 01/31/2025
4+
ms.date: 02/12/2025
55
helpviewer_keywords:
66
- "collection initializers [C#], with Dictionary"
77
ms.topic: how-to
@@ -14,15 +14,15 @@ ms.assetid: 25283922-f8ee-40dc-a639-fac30804ec71
1414
A <xref:System.Collections.Generic.Dictionary%602> contains a collection of key/value pairs. Its <xref:System.Collections.Generic.Dictionary%602.Add%2A> method takes two parameters, one for the key and one for the value. One way to initialize a <xref:System.Collections.Generic.Dictionary%602>, or any collection whose `Add` method takes multiple parameters, is to enclose each set of parameters in braces as shown in the following example. Another option is to use an index initializer, also shown in the following example.
1515

1616
> [!NOTE]
17-
> The major difference between these two ways of initializing the collection is that in case of having duplicated keys, for example:
17+
> The major difference between these two ways of initializing the collection is how duplicated keys are handled, for example:
1818
>
1919
> ```csharp
2020
> { 111, new StudentName { FirstName="Sachin", LastName="Karnik", ID=211 } },
2121
> { 111, new StudentName { FirstName="Dina", LastName="Salimzianova", ID=317 } },
2222
> ```
2323
>
24-
> <xref:System.Collections.Generic.Dictionary%602.Add%2A> method will throw <xref:System.ArgumentException>: `'An item with the same key has already been added. Key: 111'`,
25-
> while the second part of example, the public read / write indexer method, will quietly overwrite the already existing entry with the same key.
24+
> <xref:System.Collections.Generic.Dictionary%602.Add%2A> method throws <xref:System.ArgumentException>: `'An item with the same key has already been added. Key: 111'`,
25+
> while the second part of example, the public read / write indexer method, quietly overwrites the already existing entry with the same key.
2626
2727
> [!TIP]
2828
> You can use AI assistance to [initialize a dictionary with GitHub Copilot](#use-github-copilot-to-initialize-a-dictionary).

0 commit comments

Comments
 (0)