csharp-linq

Review LINQ to Objects queries for deferred execution and operator selection.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-linq-cloudywing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-linq
Source: https://github.com/CloudyWing/ai-dotfiles/tree/main/skills/csharp-linq
Command: npx skills add https://github.com/CloudyWing/ai-dotfiles --skill csharp-linq-cloudywing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill reduces subtle bugs and performance pitfalls in LINQ to Objects by clarifying deferred execution, materialization timing, operator semantics, and readability conventions so developers avoid repeated enumeration and unintended side effects.

Core Features & Use Cases

  • Materialization guidance: When to call ToList or ToArray versus preserving deferred execution for single-pass scenarios.
  • Operator selection: When to use Select, SelectMany, Any, Count, First/Single variants, and how to avoid misuse.
  • Performance and readability: Recommendations for GroupBy, ToLookup, stable multi-key ordering with ThenBy, avoiding Aggregate for string building, and formatting chained calls for clarity.
  • Code review checklist: Practical rules for reviewing in-memory LINQ queries to prevent memory pressure, repeated evaluation, and hidden side effects.

Quick Start

Ask the csharp-linq skill to review a LINQ to Objects query and recommend materialization, operator changes, and formatting to improve performance and correctness.

Frequently Asked Questions about csharp-linq

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does deferred execution work in LINQ to Objects queries?

Deferred execution in LINQ to Objects means query evaluation is postponed until results are explicitly iterated. This Skill clarifies materialization timing to help you avoid repeated enumeration and unintended side effects in in-memory collections.

When should I call ToList or ToArray versus preserving deferred execution?

Call ToList or ToArray to materialize queries when you need multiple passes or repeated iteration over in-memory collections. This Skill provides actionable recommendations on when materialization is necessary versus when preserving deferred execution is more efficient.

Why should I use Any over Count for existence checks in C# LINQ?

Using Any over Count for existence checks improves LINQ performance because Any stops evaluating at the first match. This Skill recommends proper operator selection to enforce correctness and optimize in-memory collection query efficiency.

What is the best way to flatten nested collections using C# LINQ?

SelectMany is the correct LINQ operator for flattening nested collections into a single sequence. This Skill clarifies projection versus flattening operator semantics to ensure you use SelectMany correctly instead of misusing Select during code review.

Does this LINQ review skill apply to Entity Framework Core queries?

No, this Skill explicitly focuses on LINQ to Objects and code review scenarios outside EF Core. It analyzes in-memory collection queries, addressing repeated enumeration, grouping memory costs, and side effects rather than database translation.

How do I prevent side effects in LINQ projection operators?

Avoid side effects in LINQ projections by ensuring Select and other operators do not mutate external state during deferred execution. This Skill reviews in-memory queries to identify hidden side effects and enforce readable, correct LINQ chaining.