2
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かどうかをチェックし、nullなら例外を投げるメソッド

Posted at

参考

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

リファレンス

ArgumentNullException.ThrowIfNullメソッド

以下のようなコードを、

nullチェック + 例外のスロー
if (name is null)
{
    throw new ArgumentNullException(nameof(name));
}

メソッドの呼び出し1つに書き換えられます。

.NET 6以降
ArgumentNullException.ThrowIfNull(name);

nameof演算子を使って、nullになった引数名を取り出す必要もありません。

2
1
0

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
2
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?