From a78c8bcb7b5cf1e10c8e2b02a603d19b8965d618 Mon Sep 17 00:00:00 2001 From: Megha Anand <88059806+anandmeg@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:18:06 -0800 Subject: [PATCH] Update ms.custom value to the new value and add addl. highlights (#44580) * Update ms.custom value to the new value * Update ms.custom in deserialization.md * Update ms.custom in how-to.md * Update ms.custom in customize-properties.md * Update ms.custom in migrate-from-newtonsoft.md * Update how-to-convert-a-string-to-a-number.md * Add Copilot highlight to how-to-initialize-a-dictionary-with-a-collection-initializer.md * Update how-to-initialize-a-dictionary-with-a-collection-initializer.md * Add copilot highlight to concatenate-multiple-strings.md * Update docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> * Update docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md Co-authored-by: Bill Wagner --------- Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Co-authored-by: Bill Wagner --- .../how-to/concatenate-multiple-strings.md | 21 ++++++++++++++++++- .../how-to/parse-strings-using-split.md | 2 +- ...ictionary-with-a-collection-initializer.md | 21 ++++++++++++++++++- .../how-to-convert-a-string-to-a-number.md | 2 +- .../system-text-json/customize-properties.md | 2 +- .../system-text-json/deserialization.md | 2 +- .../serialization/system-text-json/how-to.md | 2 +- .../migrate-from-newtonsoft.md | 2 +- 8 files changed, 46 insertions(+), 8 deletions(-) diff --git a/docs/csharp/how-to/concatenate-multiple-strings.md b/docs/csharp/how-to/concatenate-multiple-strings.md index c41f2a6a9c6b6..ba73d17d4c47d 100644 --- a/docs/csharp/how-to/concatenate-multiple-strings.md +++ b/docs/csharp/how-to/concatenate-multiple-strings.md @@ -1,11 +1,13 @@ --- title: "How to concatenate multiple strings" description: There are multiple ways to concatenate strings in C#. Learn the options and the reasons behind different choices. -ms.date: 11/22/2024 +ms.date: 1/31/2025 helpviewer_keywords: - "joining strings [C#]" - "concatenating strings [C#]" - "strings [C#], concatenation" +ms.collection: ce-skilling-ai-copilot +ms.custom: copilot-scenario-highlight --- # How to concatenate multiple strings (C# Guide) @@ -13,6 +15,9 @@ helpviewer_keywords: [!INCLUDE[interactive-note](~/includes/csharp-interactive-note.md)] +> [!TIP] +> You can use AI assistance to [concatenate strings with GitHub Copilot](#use-github-copilot-to-concatenate-strings). + ## String literals The following example splits a long string literal into smaller strings to improve readability in the source code. The code concatenates the smaller strings to create the long string literal. The parts are concatenated into a single string at compile time. There's no run-time performance cost regardless of the number of strings involved. @@ -66,6 +71,20 @@ combines an array of words, adding a space between each word in the array: This option can cause more allocations than other methods for concatenating collections, as it creates an intermediate string for each iteration. If optimizing performance is critical, consider the [`StringBuilder`](#stringbuilder) class or the [`String.Concat` or `String.Join`](#stringconcat-or-stringjoin) method to concatenate a collection, instead of `Enumerable.Aggregate`. +## Use GitHub Copilot to concatenate strings + +You can use GitHub Copilot in your IDE to generate C# code to concatenate multiple strings. You can customize the prompt to specify strings and the method to use per your requirements. + +The following text shows an example prompt for Copilot Chat: + +```copilot-prompt +Generate C# code to use String.Format to build an output string "Hi x, today's date is y. You are z years old." where x is "John", y is today's date and z is the birthdate January 1, 2000. The final string should show date in the full format mm/dd/yyyy. Show output. +``` + +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). + +Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview). + ## See also - diff --git a/docs/csharp/how-to/parse-strings-using-split.md b/docs/csharp/how-to/parse-strings-using-split.md index b551519804cee..fcff09eb616ec 100644 --- a/docs/csharp/how-to/parse-strings-using-split.md +++ b/docs/csharp/how-to/parse-strings-using-split.md @@ -8,7 +8,7 @@ helpviewer_keywords: - "strings [C#], splitting" - "parse strings" ms.assetid: 729c2923-4169-41c6-9c90-ef176c1e2953 -ms.custom: mvc, vs-copilot-horizontal +ms.custom: mvc, copilot-scenario-highlight ms.collection: ce-skilling-ai-copilot --- # How to separate strings using String.Split in C\# diff --git a/docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md b/docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md index a886ceea79984..aba9f14efa495 100644 --- a/docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md +++ b/docs/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer.md @@ -1,10 +1,12 @@ --- title: "How to initialize a dictionary with a collection initializer" description: Learn how to initialize a dictionary in C#, using either the Add method or an index initializer. This example shows both options. -ms.date: 03/15/2024 +ms.date: 01/31/2025 helpviewer_keywords: - "collection initializers [C#], with Dictionary" ms.topic: how-to +ms.collection: ce-skilling-ai-copilot +ms.custom: copilot-scenario-highlight ms.assetid: 25283922-f8ee-40dc-a639-fac30804ec71 --- # How to initialize a dictionary with a collection initializer (C# Programming Guide) @@ -22,6 +24,9 @@ A contains a collection of key/ > method will throw : `'An item with the same key has already been added. Key: 111'`, > while the second part of example, the public read / write indexer method, will quietly overwrite the already existing entry with the same key. +> [!TIP] +> You can use AI assistance to [initialize a dictionary with GitHub Copilot](#use-github-copilot-to-initialize-a-dictionary). + ## Example In the following code example, a 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: @@ -30,6 +35,20 @@ In the following code example, a . 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`. +## Use GitHub Copilot to initialize a dictionary + +You can use GitHub Copilot in your IDE to generate C# code to initialize a dictionary with a collection initializer. You can customize the prompt to add specifics per your requirements. + +The following text shows an example prompt for Copilot Chat: + +```copilot-prompt +Generate C# code to initialize Dictionary using key-value pairs within the collection initializer. The employee class is a record class with two properties: Name and Age. +``` + +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). + +Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview). + ## See also - [Object and Collection Initializers](./object-and-collection-initializers.md) diff --git a/docs/csharp/programming-guide/types/how-to-convert-a-string-to-a-number.md b/docs/csharp/programming-guide/types/how-to-convert-a-string-to-a-number.md index 69f76e346307d..ee6bfdc763cc1 100644 --- a/docs/csharp/programming-guide/types/how-to-convert-a-string-to-a-number.md +++ b/docs/csharp/programming-guide/types/how-to-convert-a-string-to-a-number.md @@ -9,7 +9,7 @@ helpviewer_keywords: - "strings [C#], converting to int" ms.topic: how-to ms.collection: ce-skilling-ai-copilot -ms.custom: vs-copilot-horizontal +ms.custom: copilot-scenario-highlight ms.assetid: 467b9979-86ee-4afd-b734-30299cda91e3 adobe-target: true --- diff --git a/docs/standard/serialization/system-text-json/customize-properties.md b/docs/standard/serialization/system-text-json/customize-properties.md index 085228f0f7a72..05f9809d0b122 100644 --- a/docs/standard/serialization/system-text-json/customize-properties.md +++ b/docs/standard/serialization/system-text-json/customize-properties.md @@ -13,7 +13,7 @@ helpviewer_keywords: - "objects, serializing" ms.topic: how-to ms.collection: ce-skilling-ai-copilot -ms.custom: vs-copilot-horizontal +ms.custom: copilot-scenario-highlight --- # How to customize property names and values with System.Text.Json diff --git a/docs/standard/serialization/system-text-json/deserialization.md b/docs/standard/serialization/system-text-json/deserialization.md index 3e48f9f92d26d..728bf076f6b33 100644 --- a/docs/standard/serialization/system-text-json/deserialization.md +++ b/docs/standard/serialization/system-text-json/deserialization.md @@ -12,7 +12,7 @@ helpviewer_keywords: - "deserialization" ms.topic: concept-article ms.collection: ce-skilling-ai-copilot -ms.custom: vs-copilot-horizontal +ms.custom: copilot-scenario-highlight #customer intent: As a developer, I want to learn how to use System.Text.Json to deserialize JSON data. --- diff --git a/docs/standard/serialization/system-text-json/how-to.md b/docs/standard/serialization/system-text-json/how-to.md index 09971e7db275f..0e2d552c0ee7d 100644 --- a/docs/standard/serialization/system-text-json/how-to.md +++ b/docs/standard/serialization/system-text-json/how-to.md @@ -13,7 +13,7 @@ helpviewer_keywords: - "objects, serializing" ms.topic: how-to ms.collection: ce-skilling-ai-copilot -ms.custom: vs-copilot-horizontal +ms.custom: copilot-scenario-highlight adobe-target: true --- diff --git a/docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md b/docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md index 9d6a8617f7f6b..c0b9ba48e305b 100644 --- a/docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md +++ b/docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md @@ -11,7 +11,7 @@ helpviewer_keywords: ms.topic: how-to zone_pivot_groups: dotnet-version ms.collection: ce-skilling-ai-copilot -ms.custom: vs-copilot-horizontal +ms.custom: copilot-scenario-highlight --- # Migrate from Newtonsoft.Json to System.Text.Json