-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Update anonymous types article to cover tuples as preferred alternative #49534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: meaghanlewis <[email protected]>
There was a problem hiding this 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 |
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
Example
The article now includes practical comparison:
The article maintains coverage of anonymous types while clearly establishing tuples as the modern default choice.
Original prompt
💡 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