Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.ArgumentNullException: referencia práctica

System.ArgumentNullException: referencia práctica: ArgumentNullException especializa el error de un argumento obligatorio que es null; ThrowIfNull conserva el nombre de la expresión.

Versión: .NET API; verified on .NET 10.0.14

Sintaxis

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

ArgumentNullException especializa el error de un argumento obligatorio que es null; ThrowIfNull conserva el nombre de la expresión.

Úsala para exigir referencias obligatorias de inmediato al entrar en un método.

No captures la excepción solo para continuar con un valor ausente; corrige el contrato del llamador.

Puede requerirse una conversión explícita con las sobrecargas object y void*; ParamName puede indicarse manualmente.

El programa completo usa realmente System.ArgumentNullException; su stdout esperado exacto es input.

Ejemplos

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

Resultado

input

El programa completo usa realmente `System.ArgumentNullException`; su stdout esperado exacto es `input`.

Fuentes