Skip to content

Commit

Permalink
Update ms.custom value to the new value and add addl. highlights (#44580
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>

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

Co-authored-by: Bill Wagner <[email protected]>

---------

Co-authored-by: Genevieve Warren <[email protected]>
Co-authored-by: Bill Wagner <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent a1b948b commit a78c8bc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
21 changes: 20 additions & 1 deletion docs/csharp/how-to/concatenate-multiple-strings.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
---
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)

*Concatenation* is the process of appending one string to the end of another string. You concatenate strings by using the `+` operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

[!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.
Expand Down Expand Up @@ -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

- <xref:System.String>
Expand Down
2 changes: 1 addition & 1 deletion docs/csharp/how-to/parse-strings-using-split.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\#
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -22,6 +24,9 @@ A <xref:System.Collections.Generic.Dictionary%602> contains a collection of key/
> <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'`,
> 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 <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:
Expand All @@ -30,6 +35,20 @@ In the following code example, a <xref:System.Collections.Generic.Dictionary%602
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`.
## 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<int, Employee> 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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
---

Expand Down
2 changes: 1 addition & 1 deletion docs/standard/serialization/system-text-json/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a78c8bc

Please sign in to comment.