Skip to content

Commit e5e0f3e

Browse files
BillWagnerCopilotgewarren
authored
Tuples interfaces generics (#52891)
* Anonymous -> Tuples 1. **Create `fundamentals/types/tuples.md`** — New "Tuples and deconstruction" article replacing `anonymous-types.md` - Content: tier tip, tuple declaration with named elements, inferred element names (C# 7.1), tuples as return types, tuple deconstruction (tuple-specific parts merged from `deconstruct.md`), discards (brief, link to `discards.md`), tuple comparison `==`/`!=` (C# 7.3), `with` on tuples, brief "prefer tuples over anonymous types" note linking to language reference - Does NOT duplicate: full syntax reference (stays in `value-tuples.md`), user-defined `Deconstruct`/extension methods (stays in `deconstruct.md`) - Frontmatter: `ms.topic: concept`, `ai-usage: ai-assisted`, no `f1_keywords`/`helpviewer_keywords` 1. **Create `snippets/tuples/` directory** — `tuples.csproj` (net10.0) + `Program.cs` with all snippet regions. Uses Everyday C# features. *parallel with step 1* 1. **Delete `anonymous-types.md`** and **`snippets/anonymous-types/`** — replaced by tuples. *depends on steps 1–2* * Interfaces revision 1. **Revise `interfaces.md`** — Remove `helpviewer_keywords`, add `ms.topic: concept` + `ai-usage: ai-assisted` + tier tip. Keep: declaring, implementing (implicit/explicit), interface inheritance, internal interfaces. Trim: default interface members → link to advanced; static abstract → brief mention linking out. Update summary bullets. 1. **Update `snippets/interfaces/`** — `.csproj` to net10.0, modernize `interfaces.cs` with latest features. *depends on step 4* * Generics revision 1. **Revise `generics.md`** — Remove `f1_keywords`/`helpviewer_keywords`, add `ms.topic: concept` + `ai-usage: ai-assisted` + tier tip. Reframe around **consuming** generics (`List<T>`, `Dictionary<TKey,TValue>`, `Task<T>`, `Func<T,TResult>`). Add: type inference, basic constraints (`class`/`struct`/`new()`/base type, brief `Enum`/`Delegate`/`unmanaged`), collection expressions (C# 12) with spread `..`, dictionary expressions (C# 14), co-/contra-variance at consumption level (link to `covariance-contravariance/` for depth). Demote `GenericList<T>` authoring example to secondary. 1. **Update `snippets/generics/`** — `.csproj` to net10.0, rewrite `Program.cs` with consuming-focused examples. *depends on step 6* * TOC and redirects 1. **Update `docs/csharp/toc.yml`** — Change "Tuples and anonymous types" → "Tuples and deconstruction" pointing to `tuples.md`. Remove `# TODO: tuples` comment. 1. **Update `.openpublishing.redirection.csharp.json`** — Modify existing redirect (`programming-guide/.../anonymous-types.md` → `/dotnet/csharp/fundamentals/types/tuples`). Add new redirect (`fundamentals/types/anonymous-types.md` → `/dotnet/csharp/fundamentals/types/tuples`). Sort alphabetically. 1. **Update cross-references** — Fix links to `anonymous-types.md` in `csharp-version-history.md` and `value-tuples.md` to point to `tuples.md` or language reference. * fix build warning * fix links Replace links to the old anonymous types article. * Proofread and content review * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Recreate anonymous types article Recreate the anonymous types article in the programming guide section. * Update relevant links Update links to the new anonymous types article, or both the tuples and anonymous types article. * Proofread new article. * Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> * Respond to feedback. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
1 parent 1e7e2cd commit e5e0f3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+940
-584
lines changed

.openpublishing.redirection.csharp.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"redirections": [
3+
{
4+
"source_path_from_root": "/docs/csharp/fundamentals/types/anonymous-types.md",
5+
"redirect_url": "/dotnet/csharp/fundamentals/types/tuples"
6+
},
37
{
48
"source_path_from_root": "/docs/csharp/fundamentals/types/namespaces.md",
59
"redirect_url": "/dotnet/csharp/fundamentals/program-structure/namespaces"
@@ -3065,10 +3069,6 @@
30653069
"source_path_from_root": "/docs/csharp/programming-guide/arrays/passing-arrays-using-ref-and-out.md",
30663070
"redirect_url": "/dotnet/csharp/programming-guide/arrays"
30673071
},
3068-
{
3069-
"source_path_from_root": "/docs/csharp/programming-guide/classes-and-structs/anonymous-types.md",
3070-
"redirect_url": "/dotnet/csharp/fundamentals/types/anonymous-types"
3071-
},
30723072
{
30733073
"source_path_from_root": "/docs/csharp/programming-guide/classes-and-structs/classes.md",
30743074
"redirect_url": "/dotnet/csharp/fundamentals/types/classes"

docs/core/diagnostics/diagnosticsource-diagnosticlistener.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ A typical call site will look like:
6666
:::code language="csharp" source="snippets/diagnosticsource/csharp/Program.cs" id="Snippet3":::
6767

6868
Every event has a `string` name (for example, `RequestStart`), and exactly one `object` as a payload.
69-
If you need to send more than one item, you can do so by creating an `object` with properties to represent all its information. C#'s [anonymous type](../../csharp/fundamentals/types/anonymous-types.md)
69+
If you need to send more than one item, you can do so by creating an `object` with properties to represent all its information. C#'s [anonymous type](../../csharp/programming-guide/classes-and-structs/anonymous-types.md)
7070
feature is typically used to create a type to pass 'on the fly', and makes this scheme very
7171
convenient. At the instrumentation site, you must guard the call to `Write()` with an `IsEnabled()` check on
7272
the same event name. Without this check, even when the instrumentation is inactive, the rules

docs/csharp/fundamentals/object-oriented/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ You can instantiate and initialize class or struct objects, and collections of o
8686

8787
## Anonymous Types
8888

89-
In situations where it isn't convenient or necessary to create a named class you use anonymous types. Named data members define anonymous types. For more information, see [Anonymous types](../types/anonymous-types.md).
89+
In situations where it isn't convenient or necessary to create a named class, you can use anonymous types or [tuples](../types/tuples.md). Named data members define anonymous types. Tuples are the preferred choice for new code because they offer better performance and deconstruction support. For more information, see [Tuples and deconstruction](../types/tuples.md).
9090

9191
## Extension Members
9292

docs/csharp/fundamentals/types/anonymous-types.md

Lines changed: 0 additions & 141 deletions
This file was deleted.

docs/csharp/fundamentals/types/enums.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "C# Enumerations"
33
description: Learn how to define and use enumeration types in C#, including declaring enums, using them in switch expressions, working with bit flags, and converting between enums and integers.
4-
ms.date: 03/24/2026
4+
ms.date: 04/10/2026
55
ms.topic: concept-article
66
ai-usage: ai-assisted
77
---
@@ -12,7 +12,7 @@ ai-usage: ai-assisted
1212
>
1313
> **Experienced in another language?** C# enums work similarly to enums in Java or C++, with additional support for bit flags and pattern matching. Skim the [flags](#bit-flags) and [switch expression](#use-enums-in-switch-expressions) sections for C#-specific patterns.
1414
15-
An *enumeration type* (or *enum*) defines a set of named constants backed by an integer value. Use enums when a value must be one of a fixed set of optionsdays of the week, HTTP status codes, log levels, or directions. Enums make your code more readable and less error-prone than raw integer constants because the compiler enforces the named values.
15+
An *enumeration type* (or *enum*) defines a set of named constants backed by an integer value. Use enums when a value must be one of a fixed set of options, such as days of the week, HTTP status codes, log levels, or directions. Enums make your code more readable and less error-prone than raw integer constants because the compiler enforces the named values.
1616

1717
## Declare an enum
1818

@@ -38,7 +38,7 @@ Enums work naturally with `switch` expressions and pattern matching. The compile
3838

3939
:::code language="csharp" source="snippets/enums/Program.cs" ID="UsingSeason":::
4040

41-
The discard pattern (`_`) handles any value not explicitly listed. *Pattern matching* is a C# feature that tests a value against a shape or condition. In this example, each `case` checks whether the enum matches a specific member. Switch expressions are one of several pattern matching forms. For more information about pattern matching, see [Pattern matching](../functional/pattern-matching.md).
41+
The discard pattern (`_`) handles any value not explicitly listed. Because an enum's underlying type is an integer, a variable can hold a value that doesn't correspond to any named member. For example, `(Season)99` is valid at runtime. The discard pattern ensures the switch expression handles those unexpected values safely. *Pattern matching* is a C# feature that tests a value against a shape or condition. In this example, each `case` checks whether the enum matches a specific member. Switch expressions are one of several pattern matching forms. For more information about pattern matching, see [Pattern matching](../functional/pattern-matching.md).
4242

4343
## Bit flags
4444

@@ -54,7 +54,7 @@ The `[Flags]` attribute also affects `ToString()`. It displays combined values a
5454

5555
## Convert between enums and integers
5656

57-
Explicit casts convert between an enum and its underlying integer type:
57+
Explicit [cast expressions](../../language-reference/operators/type-testing-and-cast.md#cast-expression) convert between an enum and its underlying integer type. An explicit cast uses the `(Type)value` syntax to tell the compiler you intend the conversion:
5858

5959
:::code language="csharp" source="snippets/enums/Program.cs" ID="Conversions":::
6060

0 commit comments

Comments
 (0)