Back to Skills

csharp-nullable-types

verified

Use when C# nullable reference types, null safety patterns, and migration strategies. Use when ensuring null safety in C# code.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-csharp

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-csharp/skills/csharp-nullable-types/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-csharp/skills/csharp-nullable-types/SKILL.md -a claude-code --skill csharp-nullable-types

Installation paths:

Claude
.claude/skills/csharp-nullable-types/
Powered by add-skill CLI

Instructions

# C# Nullable Types

Master nullable reference types, null safety patterns, and migration strategies
in C# 8+. This skill covers nullable value types, nullable reference types,
null-safety annotations, operators, and best practices for writing null-safe code.

## Nullable Reference Types (C# 8+)

Nullable reference types provide compile-time null safety by distinguishing
between nullable and non-nullable reference types.

### Enabling Nullable Context

```csharp
// Project-wide in .csproj
<PropertyGroup>
    <Nullable>enable</Nullable>
</PropertyGroup>

// File-level directive
#nullable enable

public class User
{
    // Non-nullable - must be initialized
    public string Name { get; set; } = string.Empty;

    // Nullable - can be null
    public string? MiddleName { get; set; }

    // Non-nullable - must be set in constructor
    public string Email { get; set; }

    public User(string email)
    {
        Email = email;
    }
}

// Disable for legacy code
#nullable disable

public class LegacyClass
{
    public string Name { get; set; } // Warning suppressed
}

#nullable restore // Return to project default
```

### Non-nullable and Nullable References

```csharp
#nullable enable

public class PersonService
{
    // ✅ Non-nullable parameter and return type
    public string FormatName(string firstName, string lastName)
    {
        return $"{firstName} {lastName}";
    }

    // ✅ Nullable parameter
    public string FormatNameWithMiddle(string firstName, string? middleName, string lastName)
    {
        if (middleName != null)
        {
            return $"{firstName} {middleName} {lastName}";
        }
        return $"{firstName} {lastName}";
    }

    // ✅ Nullable return type
    public string? FindUserEmail(int userId)
    {
        var user = _repository.Find(userId);
        return user?.Email; // May return null
    }

    // ⚠️ Warning - possible null reference
    public string GetUpperName(string? name)
    {
        // CS8602: Possible null re

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
19132 chars