Skip to content

Remove AV2221: Use lambda expressions instead of anonymous methods#341

Open
dennisdoomen wants to merge 1 commit intodevelopfrom
copilot/pr298-remove-av2221
Open

Remove AV2221: Use lambda expressions instead of anonymous methods#341
dennisdoomen wants to merge 1 commit intodevelopfrom
copilot/pr298-remove-av2221

Conversation

@dennisdoomen
Copy link
Copy Markdown
Owner

This PR removes guideline AV2221.

It was split out of #298 so the change can be reviewed independently.

Files:

  • _rules/2221.md

Part of the replacement for #298.

Split from #298.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Or even better:

var customer = customers.FirstOrDefault(customer => customer.Name == "Tom");
Copy link
Copy Markdown
Collaborator

@bkoelman bkoelman Mar 29, 2026

Choose a reason for hiding this comment

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

Interestingly, there's a Sonar rule that warns about this, requiring a change from .FirstOrDefault to Array.Find for improved performance.

---
rule_id: 2221
rule_category: dotnet-framework-usage
title: Use lambda expressions instead of anonymous methods
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Doesn't this guidance still stand? Perhaps it's uncommon to use anonymous methods nowadays, but C# supports both styles, and there's still plenty of legacy code using the old syntax. Agreeing that lambda expressions are the preferred style within a team could still be valuable.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants