Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Modern C# language feature guidance adapted to the project's target framework. Always run
[skill:dotnet-version-detection] first to determine TFM and C# version.
Naming and style conventions -- see [skill:dotnet-csharp-coding-standards]
Async/await patterns -- see [skill:dotnet-csharp-async-patterns]
Source generator usage (GeneratedRegex, LoggerMessage) -- see [skill:dotnet-csharp-source-generators]
Cross-references: [skill:dotnet-csharp-coding-standards] for naming/style conventions,
[skill:dotnet-csharp-async-patterns] for async-specific patterns.
Quick Reference: TFM to C# Version
TFM
C#
Key Language Features
net8.0
12
Primary constructors, collection expressions, alias any type
net9.0
13
params collections, Lock type, partial properties
net10.0
14
field keyword, extension blocks, nameof unbound generics
net11.0
15 (preview)
Collection expression with() arguments
Records
Use records for immutable data transfer objects, value semantics, and domain modeling where equality is based on values
rather than identity.
Record Classes (reference type)
// Positional record: concise, immutable, value equalitypublicrecordOrderSummary(int OrderId, decimal Total, DateOnly OrderDate);
// With additional memberspublicrecordCustomer(string Name, Email)
{
DisplayName => ;
}
```text
```csharp
;
;
```text
| Use Case | Prefer |
| ------------------------------------ | ------------------------ |
| DTOs, API responses | `` |
| (, ) | ` ` |
| (, ) | `` |
| -, | ` ` |
| | `` (-) |
### -
```
= order { Total = order.Total + tax };
```csharp
---
Capture constructor parameters directly the / .
**** -- .
### ( )
```
( , <> )
{
{
logger.LogInformation(, id);
repo.GetByIdAsync(id);
}
}
```text
- Primary constructor parameters are **mutable** captures, `` fields. If immutability matters, assign to a
`` field the body.
- Do use primary constructors you need to validate parameters at construction time -- use a traditional
constructor guard clauses instead.
- For records, positional parameters become properties automatically. For classes/structs, they remain
captures.
```csharp
{
_connectionString = connectionString
?? ArgumentNullException((connectionString));
}
```text
---
Unified syntax creating collections `[...]`.
```csharp
[] numbers = [, , ];
List<> names = [, ];
ReadOnlySpan<> bytes = [, ];
[] combined = [..first, ..second, ];
List<> empty = [];
```text
Specify capacity, comparers, other constructor arguments:
```csharp
List<> nums = [(capacity: ), ..Generate()];
HashSet<> = [(comparer: StringComparer.OrdinalIgnoreCase), , ];
Dictionary<, > map = [(comparer: StringComparer.OrdinalIgnoreCase),
(, ), (, )];
```text
> **net11+ only.** Requires `<LangVersion>preview</LangVersion>`. Do use earlier TFMs.
---
``` => customer
{
{ Tier: , YearsActive: > } => ,
{ Tier: } => ,
{ Tier: } => ,
_ =>
};
```text
``` => data [> , .., > ];
=> values
{
[] => ,
[] => ,
[] =>
};
```text
``` => package
{
Letter { Weight: < } => m,
Parcel { Weight: w } w < => m + w * m,
Parcel { IsOversized: } => m,
_ => m
};
```text
---
Force callers to initialize properties at construction via initializers.
```csharp
{
Name { ; ; }
Email { ; ; }
? Phone { ; ; }
}
user = UserDto { Name = , Email = };
```
{
Reading
{
=> field;
=> field = >=
?
: ArgumentOutOfRangeException(());
}
}
```text
Replaces the manual pattern of declaring a field plus a property custom logic. Use you need validation
transformation a setter without a separate backing field.
> **net10+ only.** On earlier TFMs, use a traditional field.
---
Group extension members a type a single block.
```csharp
{
extension<T>(IEnumerable<T> source) T :
{
=> source.Where(x => x );
=> !source.Any();
}
}
```text
> **net10+ only.** On earlier TFMs, use traditional `` extension methods.
---
```csharp
Point = ( X, Y);
UserId = System.Guid;
Point origin = (, );
UserId id = UserId.NewGuid();
```text
Useful tuple aliases domain type aliases without creating a full type.
---
`` now supports additional collection types beyond arrays, including `Span<T>`, `ReadOnlySpan<T>`, types
implementing certain collection interfaces.
```
{
( msg messages)
Console.WriteLine(msg);
}
Log(, );
```text
> **net9+ only.** On net8, `` only supports arrays.
---
Use `System.Threading.Lock` instead of `` locking.
```csharp
Lock _lock = ();
{
(_lock)
{
}
}
```text
`Lock` provides a `Scope`-based API advanced scenarios more expressive than ` ()`.
> **net9+ only.** On net8, use ` _gate = ();` ` (_gate)`.
---
Partial properties enable source generators to define property signatures that users implement, vice versa.
```csharp
{
Name { ; ; }
}
{
_name = ;
Name
{
=> _name;
=> SetProperty( _name, );
}
}
```text
> **net9+ only.** See [skill:dotnet-csharp-source-generators] generator patterns.
---
```csharp
name = (List<>);
name2 = (Dictionary<,>);
```csharp
Useful logging, diagnostics, reflection scenarios.
> **net10+ only.**
---
When targeting multiple TFMs, newer language features may compile older targets. Use these approaches:
**PolySharp** -- Polyfills compiler- { => field; => field = Math.Max(, ); }
_value;
Value { => _value; => _value = Math.Max(, ); }
```text
See [skill:dotnet-multi-targeting] comprehensive polyfill guidance.
---
Feature guidance skill grounded publicly available language design rationale :
- **C
rationale relevant to skill: ; use
fields immutability needed. Source: https:
- **C
features. Source: https:
> **Note:** This skill applies publicly documented design rationale. It does represent speak the named
> sources.
**Primary approach:** Use Serena symbol operations efficient code navigation:
**Find definitions**: `serena_find_symbol` instead of text search
**Understand structure**: `serena_get_symbols_overview` organization
**Track references**: `serena_find_referencing_symbols` impact analysis
**Precise edits**: `serena_replace_symbol_body` clean modifications
**When to use Serena vs traditional tools:**
- ✅ **Use Serena**: Navigation, refactoring, dependency analysis, precise edits
- ✅ **Use Read/Grep**: Reading full files, pattern matching, simple text operations
- ✅ **Fallback**: If Serena unavailable, traditional tools work fine
**Example workflow:**
```text
Read: src/Services/OrderService.cs
Grep:
serena_find_symbol:
serena_get_symbols_overview:
```
- [C
- [Whats C
- [What
string
public
string
$"{Name} <{Email}>"
### Record Structs (value type, C# 10+)
// Positional record struct: value type with value semantics
// Explicit readonly field when immutability matters
publicclassConfig(string connectionString)
private
readonly
string
throw
new
nameof
## Collection Expressions (C# 12+, net8.0+)
for
with
// Array
int
1
2
3
// List
string
"Alice"
"Bob"
// Span
byte
0x00
0xFF
// Spread operator
int
99
// Empty collection
int
### Collection Expression with Arguments (C# 15 preview, net11.0+)
or
// Capacity hint
int
with
1000
// Custom comparer
string
set
with
"Alice"
"bob"
// Dictionary with comparer
string
int
with
new
"key1"
1
new
"key2"
2
.0
not
on
## Pattern Matching
### Switch Expressions (C# 8+)
csharp
stringGetDiscount(Customer customer)
switch
"Gold"
5
"30%"
"Gold"
"20%"
"Silver"
"10%"
"0%"
### List Patterns (C# 11+)
csharp
boolIsValid(int[] data)
is
0
0
// first and last positive
stringDescribe(int[] values)
switch
"empty"
var single
$"single: {single}"
var first, .., var last
$"range: {first}..{last}"
### Type and Property Patterns
csharp
decimalCalculateShipping(object package)
switch
50
0.50
var
when
1000
5.00
0.01
true
25.00
10.00
## `required` Members (C# 11+)
object
public
class
UserDto
public
required
string
get
init
public
required
string
get
init
public
string
get
init
// Compiler enforces Name and Email
var
new
"Alice"
"alice@example.com"
text
Useful for DTOs that need to be deserialized (System.Text.Json honors `required` in .NET 8+).
---
## `field` Keyword (C# 14, net10.0+)
Access the compiler-generated backing field directly in property accessors.
```csharp
publicclass TemperatureSensor
// Callers: compiler may avoid heap allocation with span-based params
"hello"
"world"
.0
.0
params
## `Lock` Type (C# 13, net9.0+)
object
for
private
readonly
new
publicvoidDoWork()
lock
// thread-safe operation
for
and
is
lock
object
.0
.0
private
readonly
object
new
and
lock
## Partial Properties (C# 13, net9.0+)
or
// In generated file
public
partial
class
ViewModel
public
partial
string
get
set
// In user file
public
partial
class
ViewModel
private
string
""
public
partial
string
get
set
ref
value
.0
for
## `nameof` for Unbound Generic Types (C# 14, net10.0+)
string
nameof
// "List"
string
nameof
// "Dictionary"
in
and
.0
## Polyfill Guidance for Multi-Targeting
not
on
1.
requiredtypes (`IsExternalInit`, `RequiredMemberAttribute`, etc.) so language
features like `init`, `required`, and `record` work on older TFMs.
2. **Polyfill** -- Polyfills runtime APIs (e.g., `string.Contains(char)` for netstandard2.0).
3. **Conditional compilation** -- Use `#if` for features that cannot be polyfilled:
```csharp
#if NET10_0_OR_GREATER
// Use field keywordpublicdouble Value
get
set
0
value
#else
private
double
public
double
get
set
0
value
#endif
for
## Knowledge Sources
in
this
is
in
from
# Language Design Notes (Mads Torgersen et al.)** -- Design decisions behind each C# version's features. Key
this
primary constructors (reducing boilerplate for DI-heavy services), collection
expressions (unifying collection initialization syntax), `field` keyword (eliminating backing field ceremony), and
extension blocks (grouping extensions by target type). Each feature balances expressiveness with safety -- e.g.,
primary constructor parameters are intentionally mutable captures (notreadonly) to keep the feature simple
explicit
readonly
when
is
//github.com/dotnet/csharplang/tree/main/meetings
# Language Proposals Repository** -- Detailed specifications and design rationale for accepted and proposed
's new in C# 14](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14)
- [C# Language Design Notes](https://github.com/dotnet/csharplang/tree/main/meetings)
- [.NET Framework Design Guidelines](https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/)