csharp
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.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/csharp/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I write cleaner C# code for handling lists?β
5 new skills a week. 1 minute to read.
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.
Technical 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
- #5889
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets 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.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.