Complete AI TrainingYourJobSkills for your job

Skills / super-code

csharp

Language-specific super-code guidelines for csharp.

C#: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for csharp.

Table of Contents

  1. [LINQ & Collections](#linq)
  2. [Null Handling](#nulls)
  3. [Async/Await](#async)
  4. [Records & Pattern Matching](#records)
  5. [Error Handling](#errors)
  6. [Resource Management](#resources)
  7. [Anti-patterns specific to C#](#antipatterns)

1. LINQ & Collections {#linq}

// ❌ Imperative accumulation
var result = new List<string>();
foreach (var item in items) {
    if (item.IsActive) result.Add(item.Name.ToUpper());
}

// ✅
var result = items
    .Where(i => i.IsActive)
    .Select(i => i.Name.ToUpper())
    .ToList();
// ❌ Manual grouping
var grouped = new Dictionary<string, List<Item>>();
foreach (var item in items) {
    if (!grouped.ContainsKey(item.Category))
        grouped[item.Category] = new List<Item>();
    grouped[item.Category].Add(item);
}

// ✅
var grouped = items.GroupBy(i => i.Category)
    .ToDictionary(g => g.Key, g => g.ToList());
// ❌ Checking Any() then First()
if (items.Any(i => i.IsValid)) {
    var first = items.First(i => i.IsValid);
}

// ✅
var first = items.FirstOrDefault(i => i.IsValid);
if (first is not null) { ... }

Prefer method syntax for chains of 2+ operations. Query syntax is fine for complex joins.


Subscribers only

The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.

Details

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

c

Language-specific super-code guidelines for c.

cpp

Language-specific super-code guidelines for cpp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.

go

Language-specific super-code guidelines for go.