Skip to content

Commit 7efdec8

Browse files
authored
Remove section calling out using AI to initialize a dictionary (#48675)
1 parent 48ee116 commit 7efdec8

File tree

1 file changed

+0
-18
lines changed

1 file changed

+0
-18
lines changed

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ms.date: 02/12/2025
55
helpviewer_keywords:
66
- "collection initializers [C#], with Dictionary"
77
ms.topic: how-to
8-
ms.custom: copilot-scenario-highlight
98
ms.assetid: 25283922-f8ee-40dc-a639-fac30804ec71
109
---
1110
# How to initialize a dictionary with a collection initializer (C# Programming Guide)
@@ -23,9 +22,6 @@ A <xref:System.Collections.Generic.Dictionary%602> contains a collection of key/
2322
> <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'`,
2423
> while the second part of example, the public read / write indexer method, quietly overwrites the already existing entry with the same key.
2524
26-
> [!TIP]
27-
> You can use AI assistance to [initialize a dictionary](#use-ai-to-initialize-a-dictionary).
28-
2925
## Example
3026
3127
In the following code example, a <xref:System.Collections.Generic.Dictionary%602> is initialized with instances of type `StudentName`. The first initialization uses the `Add` method with two arguments. The compiler generates a call to `Add` for each of the pairs of `int` keys and `StudentName` values. The second uses a public read / write indexer method of the `Dictionary` class:
@@ -34,20 +30,6 @@ In the following code example, a <xref:System.Collections.Generic.Dictionary%602
3430
3531
Note the two pairs of braces in each element of the collection in the first declaration. The innermost braces enclose the object initializer for the `StudentName`, and the outermost braces enclose the initializer for the key/value pair to be added to the `students` <xref:System.Collections.Generic.Dictionary%602>. Finally, the whole collection initializer for the dictionary is enclosed in braces. In the second initialization, the left side of the assignment is the key and the right side is the value, using an object initializer for `StudentName`.
3632
37-
## Use AI to initialize a dictionary
38-
39-
You can use AI tools, such as GitHub Copilot, to generate C# code to initialize a dictionary with a collection initializer. You can customize the prompt to add specifics per your requirements.
40-
41-
The following text shows an example prompt for Copilot Chat:
42-
43-
```copilot-prompt
44-
Generate C# code to initialize Dictionary<int, Employee> using key-value pairs within the collection initializer. The employee class is a record class with two properties: Name and Age.
45-
```
46-
47-
GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).
48-
4933
## See also
5034
5135
- [Object and Collection Initializers](./object-and-collection-initializers.md)
52-
- [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states)
53-
- [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview)

0 commit comments

Comments
 (0)