CKTIS / C#
System.ArgumentNullException: praktická referencia
System.ArgumentNullException: praktická referencia: ArgumentNullException špecializuje chybu povinného argumentu, ktorý je null; ThrowIfNull zachová názov výrazu.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.ArgumentNullException /* select a documented member or constructor */ArgumentNullException špecializuje chybu povinného argumentu, ktorý je null; ThrowIfNull zachová názov výrazu.
Použite na okamžité vynútenie povinných referencií na vstupe metódy.
Nezachytávajte výnimku iba preto, aby ste pokračovali s chýbajúcou hodnotou; opravte kontrakt volajúceho.
Pri preťaženiach object a void* môže byť potrebné explicitné pretypovanie; ParamName možno zadať ručne.
Úplný program skutočne používa System.ArgumentNullException; presne očakávaný stdout je input.
Príklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
try { ArgumentNullException.ThrowIfNull((object?)null, "input"); } catch (ArgumentNullException error) { Console.WriteLine(error.ParamName); }
Výsledok
input
Úplný program skutočne používa `System.ArgumentNullException`; presne očakávaný stdout je `input`.