csharp

C# programming for .NET, ASP.NET Core, LINQ, async patterns, and Entity Framework. Use for .cs files.

7 stars

Best use case

csharp is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

C# programming for .NET, ASP.NET Core, LINQ, async patterns, and Entity Framework. Use for .cs files.

Teams using csharp should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/csharp/SKILL.md --create-dirs "https://raw.githubusercontent.com/G1Joshi/Agent-Skills/main/skills/languages/csharp/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/csharp/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How csharp Compares

Feature / AgentcsharpStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

C# programming for .NET, ASP.NET Core, LINQ, async patterns, and Entity Framework. Use for .cs files.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# C#

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

## When to Use

- Working with `.cs` files
- Building ASP.NET Core web APIs
- Unity game development
- Desktop apps with WPF/MAUI

## Quick Start

```csharp
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 & Nullable

```csharp
// Records for immutable data
public record User(string Id, string Name, string Email)
{
    public string DisplayName => Name.ToUpperInvariant();
}

// With-expressions for copies
var updated = user with { Name = "New Name" };

// Nullable reference types
public User? FindUser(string id)
{
    return users.FirstOrDefault(u => u.Id == id);
}
```

### Async/Await

```csharp
public async Task<List<User>> GetUsersAsync()
{
    // Parallel async operations
    var tasks = ids.Select(id => GetUserAsync(id));
    var users = await Task.WhenAll(tasks);
    return users.ToList();
}

// Async streams
public async IAsyncEnumerable<User> StreamUsersAsync()
{
    await foreach (var user in _repository.GetAllAsync())
    {
        yield return user;
    }
}

// Cancellation
public async Task<User> GetUserAsync(string id, CancellationToken ct)
{
    return await _client.GetFromJsonAsync<User>($"/users/{id}", ct);
}
```

## Common Patterns

### LINQ

```csharp
// 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

```csharp
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**:

- Use `record` for DTOs and value objects
- Enable nullable reference types
- Use async/await for I/O operations
- Use dependency injection

**Don't**:

- Block async code with `.Result` or `.Wait()`
- Ignore cancellation tokens
- Use `dynamic` when type is known
- Create God classes

## Troubleshooting

| Error                     | Cause                   | Solution                    |
| ------------------------- | ----------------------- | --------------------------- |
| `NullReferenceException`  | Accessing null          | Enable nullable, use `?.`   |
| `ObjectDisposedException` | Using disposed resource | Check lifetime, use `using` |
| `TaskCanceledException`   | Operation cancelled     | Handle or propagate         |

## References

- [Microsoft .NET Docs](https://docs.microsoft.com/dotnet/)
- [C# Programming Guide](https://docs.microsoft.com/dotnet/csharp/)