🎯

csharp

🎯Skill
g1joshi/agent-skills2 Installs9Last Updated Feb 10, 2026

Installation

$npx skills add g1joshi/agent-skills --skill csharp

Run it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).

Uses skills.sh Β· Node.js 22.20+

After installing

Ask for related work and the agent uses it on its own, or call it yourself.

Run it (Claude Code)/csharp
Install by hand

Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.

Open the skill folder β†’
  • This project .claude/skills/csharp/
  • All projects ~/.claude/skills/csharp/

These paths are for Claude Code. For other tools, the command above puts it in the right place.

Expert C# and .NET assistance covering LINQ, async/await patterns, pattern matching, records, Entity Framework Core, and ASP.NET Core web services. Use when writing idiomatic C#, designing .NET enterprise backends, building cross-platform services, or optimizing memory with span/memory types.

C#

Modern C# development with .NET 8+, async patterns, and Entity Framework.

When to Use

  • Enterprise Web Backends & Microservices: Building high-throughput ASP.NET Core web APIs and gRPC microservices on modern .NET 8/9.
  • Cross-Platform Mobile & Desktop (MAUI): Compiling native iOS, Android, macOS, and Windows applications from a single C# codebase.
  • Cloud-Native AWS & Azure Infrastructure: Deploying scalable serverless functions, containerized workers, and event-driven apps.
  • Game Development with Unity / Godot: Developing gameplay logic, physics, and state machines in leading game engines.

Quick Start

public record User(string Id, string Name, string Email);

public class UserService
{
    public async Task<User?> GetUserAsync(string id)
    {
        return await _repository.FindByIdAsync(id);
    }
}

Core Concepts

Records & Pattern Matching (C# 12/13)

Immutable data structures with value equality and expressive switch expressions:

// Positional Record with built-in value equality
public record Order(string Id, decimal Amount, string Status);

public static class OrderClassifier
{
    public static string Evaluate(Order order) => order switch
    {
        { Status: "PAID", Amount: > 1000 } => "High-Value Order",
        { Status: "PAID" }                 => "Standard Order",
        { Status: "CANCELLED" }            => "Void Order",
        _                                  => "Pending Review"
    };
}

Memory Optimization with Span<T> and ReadOnlySpan<T>

Allocates and slices continuous memory buffers on the stack without heap GC allocations:

public static bool TryParseYear(ReadOnlySpan<char> dateSpan, out int year)
{
    // Slice without allocating new sub-strings
    ReadOnlySpan<char> yearSpan = dateSpan.Slice(0, 4);
    return int.TryParse(yearSpan, out year);
}

Async / Await with ValueTask

Efficient asynchronous programming minimizing task object allocations on hot paths:

public async ValueTask<UserProfile> GetUserProfileAsync(string userId)
{
    if (_cache.TryGetValue(userId, out var cached))
        return cached; // Synchronous return allocates zero task objects

    return await _repository.FetchFromDatabaseAsync(userId);
}

Common Patterns

Declarative Data Transformations with LINQ

Problem: Imperative nested loops and mutation when filtering, projecting, and sorting collections.

Solution:

// Query syntax
var adults = from user in users
             where user.Age >= 18
             orderby user.Name
             select user;

// Method syntax (preferred)
var result = users
    .Where(u => u.IsActive)
    .OrderBy(u => u.Name)
    .Select(u => new UserDto(u.Id, u.Name))
    .ToList();

// Grouping
var byCountry = users
    .GroupBy(u => u.Country)
    .ToDictionary(g => g.Key, g => g.ToList());

Pattern Matching

Problem: Verbose cascading conditional checks and manual type casting leading to runtime type errors.

Solution:

string GetStatus(object obj) => obj switch
{
    User { IsActive: true } => "Active user",
    User { IsActive: false } => "Inactive user",
    null => "No data",
    _ => "Unknown"
};

// List patterns
if (numbers is [var first, _, var last])
{
    Console.WriteLine($"First: {first}, Last: {last}");
}

Best Practices

Do:

  • Enable Nullable Reference Types (<Nullable>enable</Nullable>): Catch null reference exceptions at compile time across the codebase.
  • Use Dependency Injection & Options Pattern: Inject strongly-typed configurations via IOptions<T> and constructor injection.
  • Use ValueTask<T> on Frequently Cached Code Paths: Reduce GC allocations by returning ValueTask when operations often complete synchronously.
  • Leverage Native AOT Compilation: Compile .NET applications to native machine code (PublishAot=true) for sub-10ms startup and tiny memory footprints.

Don't:

  • Block async code with .Result or .Wait(): Synchronous blocking on asynchronous tasks causes immediate thread pool deadlocks.
  • Use mutable shared singletons without thread safety: Use ConcurrentDictionary or proper synchronization primitives.
  • Instantiate HttpClient per request: Use IHttpClientFactory to prevent socket exhaustion.

Troubleshooting

ErrorCauseSolution
NullReferenceExceptionAccessing nullEnable nullable, use ?.
ObjectDisposedExceptionUsing disposed resourceCheck lifetime, use using
TaskCanceledExceptionOperation cancelledHandle or propagate

References

More from this repository10