Skip to content
Skills Library
Programming · Learning & explanation

csharp

/csharp

C# 12 language features including records, pattern matching, nullable reference types, LINQ, async/await, and modern language patterns. USE WHEN: user mentions "C#", "C# records", "pattern matching", "LINQ", "async/await", "nullable reference types", "C# generics", "C# language features" DO NOT USE FOR: reviewing existing C# code - use `review/csharp`, which covers async, disposal and the guarantees that are opt-in per project DO NOT USE FOR: TypeScript - use `typescript`, Java - use Java skills, F# or VB.NET specific features

Licence
MIT
Last repository change
21.10.2026

Assessment and security

95/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content30 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

C# 12 language features including records, pattern matching, nullable reference types, LINQ, async/await, and modern language patterns. USE WHEN: user mentions "C#", "C# records", "pattern matching", "LINQ", "async/await", "nullable reference types", "C# generics", "C# language features" DO NOT USE FOR: reviewing existing C# code - use `review/csharp`, which covers async, disposal and the guarantees that are opt-in per project DO NOT USE FOR: TypeScript - use `typescript`, Java - use Java skills, F# or VB.NET specific features

Triggers from the description

C# recordspattern matchingLINQasync/awaitnullable reference typesC# genericsC# language features
Original author description

C# 12 language features including records, pattern matching, nullable reference types, LINQ, async/await, and modern language patterns. USE WHEN: user mentions "C#", "C# records", "pattern matching", "LINQ", "async/await", "nullable reference types", "C# generics", "C# language features" DO NOT USE FOR: reviewing existing C# code - use `review/csharp`, which covers async, disposal and the guarantees that are opt-in per project DO NOT USE FOR: TypeScript - use `typescript`, Java - use Java skills, F# or VB.NET specific features

How it works

  1. Records
  2. Pattern Matching (C 12)
  3. Nullable Reference Types
  4. Async/Await Patterns
  5. LINQ
  6. Primary Constructors (C 12)
  7. Collection Expressions (C 12)
  8. Anti-Patterns
  9. Quick Troubleshooting
Original SKILL.md headings · 192 lines, 695 words
SKILL.md preview
---
name: csharp
description: |
  C# 12 language features including records, pattern matching, nullable reference types,
  LINQ, async/await, and modern language patterns.

  USE WHEN: user mentions "C#", "C# records", "pattern matching", "LINQ", "async/await",
  "nullable reference types", "C# generics", "C# language features"

  DO NOT USE FOR: reviewing existing C# code - use `review/csharp`, which covers
  async, disposal and the guarantees that are opt-in per project
  DO NOT USE FOR: TypeScript - use `typescript`, Java - use Java skills,
  F# or VB.NET specific features
allowed-tools: Read, Grep, Glob, Write, Edit
---
# C# 12 - Quick Reference

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `csharp` for comprehensive documentation.

## Records

```csharp
// Positional record (immutable)
public record UserDto(int Id, string Name, string Email);

// Record with additional members
public record OrderDto(int Id, decimal Total)
{
    public string FormattedTotal => Total.ToString("C");
}

// Record struct (value type, C# 10)
public readonly record struct Point(double X, double Y);

// With-expression (non-destructive mutation)
var updated = user with { Name = "New Name" };
```

## Pattern Matching (C# 12)

```csharp
// Switch expression
string GetDiscount(Customer customer) => customer switch
{
    { Type: CustomerType.Premium, YearsActive: > 5 } => "30%",
    { Type: CustomerType.Premium } => "20%",
    { Type: CustomerType.Regular, YearsActive: > 3 } => "10%",
    _ => "0%",
};

// List patterns (C# 11)
var result = numbers switch
{
    [1, 2, 3] => "exact match",
    [1, .., 3] => "starts with 1, ends with 3",
    [_, > 5, ..] => "second element > 5",
    [] => "empty",
    _ => "other",
};

// Type pattern with when
if (shape is Circle { Radius: > 10 } circle)
{
    Console.WriteLine($"Large circle: {circle.Radius}");
}
```

## Nullable Reference Types

```csharp
// Enable in .csproj: <Nullable>enable</Nullable>

public class UserService
{
    // Nullable return type
    public User? FindById(int id) => _users.FirstOrDefault(u => u.Id == id);

    // Non-nullable parameter
    public void Update(User user)
    {
        ArgumentNullException.ThrowIfNull(user);
        // user is guaranteed non-null here
    }

    // Null-conditional and coalescing
    public string GetDisplayName(User? user)
        => user?.Name ?? "Unknown";

    // Required members (C# 11)
    public required string Name { get; init; }
}
```

## Async/Await Patterns

```csharp
// Basic async method
public async Task<User> GetUserAsync(int id)
{
    var user = await _repository.FindAsync(id);
    return user ?? throw new NotFoundException($"User {id} not found");
}

// Parallel async
public async Task<(User[], Order[])> GetDashboardDataAsync(int userId)
{
    var usersTask = _userService.GetAllAsync();
    var ordersTask = _orderService.GetByUserAsync(userId);
    await Task.WhenAll(usersTask, ordersTask);
    return (usersTask.Result, ordersTask.Result);
}

// IAsyncEnumerable
public async IAsyncEnumerable<User> GetUsersStreamAsync(
    [EnumeratorCancellation] CancellationToken ct = default)
{
    await foreach (var user in _context.Users.AsAsyncEnumerable().WithCancellation(ct))
    {
        yield return user;
    }
}

// ValueTask for hot paths
public ValueTask<User?> GetCachedUserAsync(int id)
{
    if (_cache.TryGetValue(id, out var user))
        return ValueTask.FromResult<User?>(user);
    return new ValueTask<User?>(LoadUserAsync(id));
}
```

## LINQ

```csharp
// Method syntax (preferred)
var result = users
    .Where(u => u.IsActive)
    .OrderBy(u => u.Name)
    .Select(u => new { u.Name, u.Email })
    .ToList();

// GroupBy
var grouped = orders
    .GroupBy(o => o.Status)
    .Select(g => new { Status = g.Key, Count = g.Count(), Total = g.Sum(o => o.Amount) });

// Aggregate
var summary = orders.Aggregate(
    new { Count = 0, Total = 0m },
    (acc, order) => new { Count = acc.Count + 1, Total = acc.Total + order.Amount });

// Chunk (C# 12 / .NET 8)
var batches = users.Chunk(100); // IEnumerable<User[]>
```

## Primary Constructors (C# 12)

```csharp
// Class primary constructor
public class UserService(IUserRepository repository, ILogger<UserService> logger)
{
    public async Task<User> GetByIdAsync(int id)
    {
        logger.LogInformation("Getting user {Id}", id);
        return await repository.GetByIdAsync(id)
            ?? throw new NotFoundException($"User {id} not found");
    }
}

// Record primary constructor (already existed)
public record UserDto(int Id, string Name, string Email);
```

## Collection Expressions (C# 12)

```csharp
// Array
int[] numbers = [1, 2, 3, 4, 5];

// List
List<string> names = ["Alice", "Bob", "Charlie"];

// Spread
int[] first = [1, 2, 3];
int[] second = [4, 5, 6];
int[] combined = [..first, ..second]; // [1, 2, 3, 4, 5, 6]
```

## Anti-Patterns

| Anti-Pattern | Why It's Bad | Correct Approach |
|--------------|--------------|------------------|
| `.Result` / `.Wait()` | Deadlocks | Use `async/await` |
| `async void` | Exceptions lost | Use `async Task` |
| Mutable DTOs | Unexpected mutations | Use `record` types |
| No null checking | NullReferenceException | Enable nullable references |
| String concatenation in loops | Memory pressure | Use `StringBuilder` |

## Quick Troubleshooting

| Issue | Likely Cause | Solution |
|-------|--------------|----------|
| Nullable warning | Missing null check | Add `?`, `??`, or null guard |
| Deadlock | `.Result` in async context | Use `await` |
| LINQ multiple enumeration | Iterating IEnumerable twice | Call `.ToList()` first |
| Record equality fails | Reference type property | Override `Equals` or use value types |

Versions

RepositoryScoreLicence
This page · claude-dev-suite/claude-dev-suite95MIT
alexander-danilenko/cortex-claude-code-plugins100MIT
G1Joshi/Agent-Skills100MIT
pingqLIN/skill-096MIT

Database snapshot: 13.11.2026 · package version 05c2f9289c27 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100csharp-idioms
    Modern C# (10+/.NET) coding idioms: nullable reference types, records, pattern matching, async/await with CancellationTokens, LINQ performance, and DI. Use when writing, modifying, or reviewing C# application code or domain models. Pair with dotnet-idioms for framework APIs.
  • 95lang-csharp
    Use this skill when the user says 'C#', 'csharp', '.NET', 'dotnet', 'async await C#', 'LINQ', 'nullable reference types', 'Span<T>', 'records', 'pattern matching', 'IDisposable', 'xUnit', 'NuGet', 'dotnet CLI'. Writes and reviews modern C# on current .NET (LTS .NET 10): language…
  • 100csharp-guide
    C# language guardrails, patterns, and best practices for AI-assisted development. Use when working with C# files (.cs, .csx), .csproj, .sln, or when the user mentions C#/.NET. Provides nullable reference types, async/await patterns, LINQ guidelines, and testing standards…
  • 100csharp-dotnet
    Use when building on .NET 8+ with C# 12. Covers nullable reference types, records, async/await correctness, minimal APIs, dependency injection, and EF Core query performance. Trigger on "async deadlock in my asp.net app", "turn on nullable reference types", "ef core is doing n+1…
  • 90neo-csharp
    Use this skill when writing, reviewing, debugging, or modernizing C# code in .NET projects. Trigger for .cs/.csproj files, C# language-version questions, nullable reference types, records, pattern matching, async/cancellation, or version-appropriate syntax from C# 10+.
  • 100csharp-expert
    Expert-level C# development with .NET 8+, ASP.NET Core, LINQ, async/await, and enterprise patterns. Use when the user mentions C#, .NET, ASP.NET, enterprise, or Microsoft platforms, or when the task involves Modern C#, Async/Await, LINQ, or ASP.NET Core.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.