Skip to content

Commit 4423d2e

Browse files
authored
Update to add revised AI use case (#49139)
* Update to add revised AI use case * Add custom tag for Copilot scenario highlighting Added a custom tag for highlighting Copilot scenarios.
1 parent 9676490 commit 4423d2e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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: 02/12/2025
4+
ms.date: 10/14/2025
55
helpviewer_keywords:
66
- "collection initializers [C#], with Dictionary"
77
ms.topic: how-to
88
ms.assetid: 25283922-f8ee-40dc-a639-fac30804ec71
9+
ms.custom: copilot-scenario-highlight
910
---
1011
# How to initialize a dictionary with a collection initializer (C# Programming Guide)
1112

@@ -30,6 +31,25 @@ In the following code example, a <xref:System.Collections.Generic.Dictionary%602
3031
3132
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`.
3233
34+
## Use AI to generate test data for dictionary collections
35+
36+
You can use AI tools, such as GitHub Copilot, to quickly generate dictionary test data and validation scenarios in your C# projects.
37+
38+
Here's an example prompt you can use in Visual Studio Copilot Chat.
39+
40+
```copilot-prompt
41+
Generate data collections for tests to create a separate Dictionary<int, Student> containing 10 valid Student records and 5 invalid records.
42+
- Valid records should have realistic Name and Grade values.
43+
- Invalid records should include cases such as missing Name, Grade < 0, or Grade > 100.
44+
- This dictionary should be used only for testing purposes and not modify existing production code.
45+
- Generate test code that utilizes this test data for validation scenarios.
46+
- Call test method to run the test.
47+
```
48+
49+
Review Copilot's suggestions before applying them.
50+
51+
For more information about GitHub Copilot, see GitHub's [FAQs](https://github.com/features/copilot#faq).
52+
3353
## See also
3454
3555
- [Object and Collection Initializers](./object-and-collection-initializers.md)

0 commit comments

Comments
 (0)