csharp
Guides your agent to produce clean and effective C# code. This is useful for developing Windows applications and games.
What it does
This guide teaches how to write C# code more efficiently and clearly, following the language's best practices. It shows examples of how to improve parts of your code to make it easier to read and maintain.
When to use it
- ✓When learning to program in C#.
- ✓When reviewing or improving existing C# code.
- ✓When wanting to write more modern and safer C# code.
Example of what to ask your AI
“How can I write cleaner C# code for handling lists?”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
The guide compares the old way and the new way of doing things in C#. It shows code examples side-by-side, highlighting the differences and explaining why one way is better than the other.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill csharpOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/super-code/csharp/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
- LINQ & Collections
- Null Handling
- Async/Await
- Records & Pattern Matching
- Error Handling
- Resource Management
- Anti-patterns specific to C#
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.
2. Null Handling {#nulls}
// ❌ Nested null checks
string city = null;
if (user != null && user.Address != null) {
city = user.Address.City;
}
// ✅
var city = user?.Address?.City;
// ❌ Ternary for null fallback
var name = user != null ? user.Name : "Unknown";
// ✅
var name = user?.Name ?? "Unknown";
// ❌ Null check before event invocation
if (OnChanged != null) OnChanged(this, args);
// ✅
OnChanged?.Invoke(this, args);
// ❌ Throwing ArgumentNullException manually
if (name == null) throw new ArgumentNullException(nameof(name));
// ✅ (C# 10+)
ArgumentNullException.ThrowIfNull(name);
Enable nullable reference types (<Nullable>enable</Nullable>) project-wide.
3. Async/Await {#async}
// ❌ Blocking on async code
var result = GetDataAsync().Result; // deadlock risk
// ✅
var result = await GetDataAsync();
// ❌ async void (exceptions are unobservable)
async void OnButtonClick() { await DoWork(); }
// ✅ — async Task; only async void for event handlers that truly require it
async Task OnButtonClick() { await DoWork(); }
// ❌ Sequential awaits for independent work
var a = await FetchA();
var b = await FetchB();
// ✅
var (a, b) = (await Task.WhenAll(FetchA(), FetchB())) switch
{
var r => (r[0], r[1])
};
// or cleaner with ValueTuple:
var taskA = FetchA();
var taskB = FetchB();
var a = await taskA;
var b = await taskB;
// ❌ Wrapping synchronous code in Task.Run inside a library
public Task<int> GetValue() => Task.Run(() => ComputeSync());
// ✅ — let the caller decide; expose sync method
public int GetValue() => ComputeSync();
Add ConfigureAwait(false) in library code. Omit in app/UI code.
4. Records & Pattern Matching {#records}
// ❌ Manual equality, ToString, Deconstruct for data types
class Point {
public int X { get; init; }
public int Y { get; init; }
// + Equals, GetHashCode, ToString...
}
// ✅ (C# 9+)
record Point(int X, int Y);
// ❌ if-else chain for type checking
if (shape is Circle) {
var c = (Circle)shape;
return c.Radius * c.Radius * Math.PI;
} else if (shape is Rectangle) { ... }
// ✅
return shape switch {
Circle { Radius: var r } => r * r * Math.PI,
Rectangle { Width: var w, Height: var h } => w * h,
_ => throw new ArgumentException($"Unknown shape: {shape}")
};
// ❌ Range checking with &&
if (score >= 0 && score <= 100) { ... }
// ✅ (C# 9+)
if (score is >= 0 and <= 100) { ... }
5. Error Handling {#errors}
// ❌ Catching Exception to log and swallow
try { Process(); }
catch (Exception ex) { logger.LogError(ex, "error"); }
// ✅ — catch specific, rethrow if you can't handle
try { Process(); }
catch (HttpRequestException ex) {
throw new ServiceException("upstream failure", ex);
}
// ❌ throw ex (resets stack trace)
catch (Exception ex) { throw ex; }
// ✅
catch (Exception ex) { throw; } // preserves stack trace
// or wrap: throw new AppException("context", ex);
…
FAQ
What is LINQ?
LINQ (Language Integrated Query) is a way to query and manipulate data collections directly within the C# language, making code more concise.
What does 'Async/Await' mean?
Async/Await are keywords that help write code that performs background tasks without freezing the main program, improving responsiveness.
What are 'Records' in C#?
Records are a special type of class in C# that simplifies creating immutable data-focused types, with features like automatic equality and string representation.
Details
Original description by the author
Language-specific super-code guidelines for csharp.
Popularity
- GitHub stars
- 48k
- Ranking position
- #4275
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC