dotnet-typeslisted
Install: claude install-skill AllThingsSmitty/agent-skills
# C# Types
C#'s type system has grown significantly — nullable reference types, records, and pattern matching change how you model data and handle null. Use them. Code written without these features tends to be both more verbose and less safe.
## Enable nullable reference types
Enable `<Nullable>enable</Nullable>` in your project file. This makes all reference types non-nullable by default — you must opt into nullability with `?`.
```xml
<!-- .csproj -->
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
```
```csharp
// Non-nullable — compiler guarantees this is never null
string name = GetName();
// Nullable — must check before use
string? email = GetEmail();
if (email is not null)
{
Send(email); // safe
}
```
Don't suppress the warnings with `!` (null-forgiving operator) unless you genuinely know more than the compiler — it's the C# equivalent of `as any`.
```csharp
// Bad: suppresses the warning without checking
string email = GetEmail()!;
// Good: check or propagate nullability
string? email = GetEmail();
string resolvedEmail = email ?? throw new InvalidOperationException("Email required");
```
## Records for immutable data
Use `record` for immutable data transfer objects, domain value types, and anything where value equality matters. Records generate `Equals`, `GetHashCode`, `ToString`, and deconstruction automatically.
```csharp
// Immutable record — value equality by default
public record UserId(string Value);
public record User(UserId Id,