-
Notifications
You must be signed in to change notification settings - Fork 6k
Add guidance for choosing ToList() vs ToArray() in async LINQ scenarios #47729
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
Conversation
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
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.
This is ready for final review.
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
PoliCheck Scan ReportThe following reports lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a comment that you post to the PR. The feedback helps reduce false positive instances in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
@gewarren This is now updated with all your feedback. Can you approve? |
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.
@copilot the full Program.cs reference at the end of the article includes the snippet system code comments because it's referencing the file with out a snippet id. Place a starting and ending snippet id (named complete) at the top and bottom of the Program.cs file, then reference it. The build system will solve the problem of showing other snippet identifiers in the published article.
Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
Head branch was pushed to by a user without write access
Fixed this issue by adding "complete" snippet markers to wrap the entire Program.cs file and updating the markdown reference to use |
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
Enhanced the async scenarios documentation to explain when to use
ToList()
versusToArray()
when forcing eager evaluation of LINQ expressions with async operations.Changes Made
Updated documentation text to provide clear guidance on choosing between the two methods:
ToArray()
forTask.WhenAll
scenarios where you process all tasks together and the collection size is fixedToList()
forTask.WhenAny
scenarios where you need to dynamically manage tasks, such as removing completed tasks from the collectionAdded practical code example demonstrating the
ToList()
approach:This example shows how
ToList()
creates a modifiable collection that supports theRemove()
operation, making it ideal forWhenAny
patterns where you handle completions as they arise.The existing
ToArray()
example and explanation remain unchanged to maintain backwards compatibility while providing developers with a complete understanding of both approaches.Fixes #34606.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
learn.microsoft.com
/home/REDACTED/work/docs/docs/docs/csharp/asynchronous-programming/snippets/async-scenarios/bin/Debug/net8.0/async-scenarios
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 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