1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Null許容参照型の警告を消す(#nullableディレクティブ)

Last updated at Posted at 2025-09-12

参考

この記事は、以下の動画を参考にしています。
詳しくは、動画をご覧ください。

Null許容コンテキスト

#nullableディレクティブ

コードの行単位で、Null許容参照型の警告を出すかどうかを、#nullableディレクティブを使ってコントロールできます。

#nullable disable
    internal static string Method()
    {
        string value = null; // 通常、警告が出るが、#nullable disableで抑制される
        return value;        // 通常、警告が出るが、#nullable disableで抑制される
    }
#nullable enable

プロジェクト単位で、Null許容参照型の警告を出すかどうかをコントロールしたい場合は、プロジェクトの設定を使います。

*.csproj
<Project Sdk="...">
    <PropertyGroup>

        <Nullable>disable</Nullable>
    </PropertyGroup>
</Project>
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?