Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / C#

System.ArgumentNullException: praktična referenca

System.ArgumentNullException: praktična referenca: ArgumentNullException specijalizira pogrešku obveznog argumenta koji je null; ThrowIfNull čuva naziv izraza.

Verzija: .NET API; verified on .NET 10.0.14

Sintaksa

System.ArgumentNullException /* select a documented member or constructor */

ArgumentNullException specijalizira pogrešku obveznog argumenta koji je null; ThrowIfNull čuva naziv izraza.

Koristite za trenutačno nametanje obveznih referenci na ulazu u metodu.

Ne hvatajte iznimku samo da biste nastavili s vrijednošću koja nedostaje; popravite ugovor pozivatelja.

Uz preopterećenja object i void* možda je potrebna izričita pretvorba; ParamName se može zadati ručno.

Cijeli program doista koristi System.ArgumentNullException; točno očekivani stdout jest input.

Primjeri

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); }

Rezultat

input

Cijeli program doista koristi `System.ArgumentNullException`; točno očekivani stdout jest `input`.

Izvori