Skip to content

Clarify that collection expressions don't support inline arrays #47736

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 5, 2025

The collection expressions documentation was causing confusion about whether inline arrays are supported. Users reported getting CS9174 errors when trying to use collection expressions with inline arrays, which is the expected behavior since inline arrays are not supported for collection expressions in C# 12.

The issue was that the conversions section mentioned "Arrays" generically, which could be interpreted to include inline arrays. This change clarifies the documentation by:

  1. Specifying regular arrays explicitly - Changed "Arrays" to "Arrays, such as int[] or string[]" to make it clear we're referring to standard arrays
  2. Adding explicit clarification - Added a NOTE section stating that collection expressions cannot be used to initialize inline arrays and that inline arrays require different initialization syntax
  3. Providing helpful cross-reference - Linked to the inline arrays documentation for users who need to learn about proper inline array initialization

The change is minimal and surgical, only adding clarification without changing any existing functionality or breaking any links. Testing confirmed that:

  • Regular arrays continue to work correctly with collection expressions
  • Inline arrays still produce CS9174 as expected when used with collection expressions
  • The documentation links resolve properly

Fixes #38916.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/operators/collection-expressions.md docs/csharp/language-reference/operators/collection-expressions

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Aug 5, 2025
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Collection Expressions Documentation Lists Convertion To Inline Array Clarify that collection expressions don't support inline arrays Aug 5, 2025
@Copilot Copilot AI requested a review from BillWagner August 5, 2025 17:47
Copilot finished work on behalf of BillWagner August 5, 2025 17:47
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review August 6, 2025 14:16
@BillWagner BillWagner requested a review from a team as a code owner August 6, 2025 14:16
@BillWagner BillWagner requested review from tdykstra and adegeo August 6, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc lang-reference/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection Expressions Documentation Lists Convertion To Inline Array
2 participants