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
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