Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

The anonymous types article was outdated and didn't address tuples, which are the preferred choice in modern C# for most scenarios where anonymous types were traditionally used.

Changes

  • Added prominent TIP callout recommending tuples as the preferred choice with clear guidance on when to use each type
  • New comparison section with table contrasting anonymous types vs tuples across key dimensions: type (reference/value), performance (heap/stack), mutability, deconstruction support, expression tree support, access modifiers, and member naming
  • When to use guidance for both types with specific scenarios
  • Code example demonstrating tuple equivalence to anonymous types with deconstruction
  • See also section linking to tuple types reference and "Choosing between anonymous and tuple types" article

Example

The article now includes practical comparison:

// Anonymous type example
var anonymousProduct = new { Name = "Widget", Price = 19.99M };
Console.WriteLine($"Anonymous: {anonymousProduct.Name} costs ${anonymousProduct.Price}");

// Equivalent using tuple with named elements
var tupleProduct = (Name: "Widget", Price: 19.99M);
Console.WriteLine($"Tuple: {tupleProduct.Name} costs ${tupleProduct.Price}");

// Tuples support deconstruction
var (productName, productPrice) = tupleProduct;
Console.WriteLine($"Deconstructed: {productName} costs ${productPrice}");

The article maintains coverage of anonymous types while clearly establishing tuples as the modern default choice.

Original prompt

This section details on the original issue you should resolve

<issue_title>Update Anonymous types article to cover tuples</issue_title>
<issue_description>### Type of issue

Outdated article

Description

Tuples server a similar purpose to anonymous types but have better language support and compile to a more efficient data structure.

Update the Anonymous types article to focus on tuples. Include the differences between the two, and why it's preferred to use tuples.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/fundamentals/types/anonymous-types.md

Document Version Independent Id

dd937177-98f0-a797-d49b-29332aae0614

Platform Id

ecfed45c-63aa-17f6-2cfc-88b1f8bc7adb

Article author

@BillWagner

Metadata

  • ID: d1b30ebe-b640-449b-3602-9891a55794db
  • PlatformId: ecfed45c-63aa-17f6-2cfc-88b1f8bc7adb
  • Service: dotnet-csharp
  • Sub-service: fundamentals

Related Issues</issue_description>

<agent_instructions>The anonymous types article should include more details about tuples. Refer to: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples and https://learn.microsoft.com/en-us/dotnet/standard/base-types/choosing-between-anonymous-and-tuple for more details. Also link to: https://learn.microsoft.com/en-us/dotnet/standard/base-types/choosing-between-anonymous-and-tuple as related content.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/fundamentals/types/anonymous-types.md Anonymous types and tuples
docs/csharp/toc.yml Taken from https://github.com/dotnet/roslyn/wiki/Samples-and-Walkthroughs

Copilot AI changed the title [WIP] Update anonymous types article to cover tuples Update anonymous types article to cover tuples as preferred alternative Oct 29, 2025
Copilot finished work on behalf of meaghanlewis October 29, 2025 19:15
Copilot AI requested a review from meaghanlewis October 29, 2025 19:15
@meaghanlewis meaghanlewis marked this pull request as ready for review November 12, 2025 23:17
@meaghanlewis meaghanlewis requested review from a team and BillWagner as code owners November 12, 2025 23:17
Copilot AI review requested due to automatic review settings November 12, 2025 23:17
Copilot finished reviewing on behalf of meaghanlewis November 12, 2025 23:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the anonymous types article to include comprehensive coverage of tuples as the preferred modern alternative. The update addresses an outdated documentation issue by establishing tuples as the default choice while maintaining thorough coverage of anonymous types for scenarios where they're still appropriate.

Key changes:

  • Added guidance positioning tuples as the preferred choice over anonymous types for most scenarios
  • Introduced a comparison table contrasting anonymous types and tuples across key dimensions (type, performance, mutability, deconstruction, expression trees, access modifiers, member names)
  • Provided expanded code examples demonstrating tuple usage, deconstruction patterns, and method return scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
docs/csharp/toc.yml Updated navigation title from "Anonymous Types" to "Anonymous types and tuples" to reflect expanded content
docs/csharp/fundamentals/types/anonymous-types.md Major content overhaul adding tuple coverage, comparison guidance, when-to-use sections, and updated examples with improved organization
docs/csharp/fundamentals/types/snippets/anonymous-types/Program.cs Added comprehensive code examples for tuples including deconstruction patterns, method returns, and dictionary usage; updated Product class properties from set to init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Anonymous types article to cover tuples

2 participants