语言

ArgumentNullException 构造函数

定义

初始化 ArgumentNullException 类的新实例。

重载

名称 说明
ArgumentNullException()

初始化 ArgumentNullException 类的新实例。

ArgumentNullException(String)

使用导致此异常的参数名称初始化类的新实例 ArgumentNullException 。

ArgumentNullException(SerializationInfo, StreamingContext)
已过时.

使用序列化的数据初始化 ArgumentNullException 类的新实例。

ArgumentNullException(String, Exception)

使用指定的错误消息和导致此异常的异常初始化类的新实例 ArgumentNullException 。

ArgumentNullException(String, String)

使用指定的错误消息和导致此异常的参数的名称初始化类的实例 ArgumentNullException 。

ArgumentNullException()

Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs

初始化 ArgumentNullException 类的新实例。

public:
 ArgumentNullException();
public ArgumentNullException();
Public Sub New ()

注解

此构造函数将 Message 新实例的属性初始化为系统提供的消息,该消息描述错误,例如“值不能为 null”。此消息将考虑当前系统区域性。

下表显示了 ArgumentNullException实例的初始属性值。

财产 价值
InnerException Null 引用(Nothing 在 Visual Basic 中)。
Message 英语的本地化错误消息字符串,例如“值不能为 null”。

适用于

ArgumentNullException(String)

Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs

使用导致此异常的参数名称初始化类的新实例 ArgumentNullException 。

public:
 ArgumentNullException(System::String ^ paramName);
public ArgumentNullException(string paramName);
public ArgumentNullException(string? paramName);
new ArgumentNullException : string -> ArgumentNullException
Public Sub New (paramName As String)

参数

paramName
String

导致异常的参数的名称。

注解

此构造函数将 Message 新实例的属性初始化为系统提供的消息,该消息描述错误并包括参数名称。 此消息将考虑当前系统区域性。

此构造函数使用ParamName参数初始化paramName新实例的属性。 paramName 的内容旨在由人类理解。

下表显示了 ArgumentNullException实例的初始属性值。

财产 价值
InnerException Null 引用(Nothing 在 Visual Basic 中)。
Message 标识 null 参数的本地化错误消息字符串。 例如,如果 paramName 参数为“arg1”,则英语消息字符串为:

在 .NET 5+ 和 .NET Core 上: Value cannot be null. (Parameter name: 'arg1')

在 .NET Framework 上: Value cannot be null.\r\nParameter name: arg1
ParamName 参数名称字符串。

适用于

ArgumentNullException(SerializationInfo, StreamingContext)

Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs

注意

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

使用序列化的数据初始化 ArgumentNullException 类的新实例。

protected:
 ArgumentNullException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ArgumentNullException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected ArgumentNullException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Security.SecurityCritical]
protected ArgumentNullException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new ArgumentNullException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentNullException
new ArgumentNullException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentNullException
[<System.Security.SecurityCritical>]
new ArgumentNullException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentNullException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo

保存序列化对象数据的对象。

context
StreamingContext

描述序列化数据的源或目标的对象。

特性

注解

在反序列化期间调用此构造函数以重新构造通过流传输的异常对象。 有关详细信息,请参阅 XML 和 SOAP 序列化。

另请参阅

适用于

ArgumentNullException(String, Exception)

Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs

使用指定的错误消息和导致此异常的异常初始化类的新实例 ArgumentNullException 。

public:
 ArgumentNullException(System::String ^ message, Exception ^ innerException);
public ArgumentNullException(string message, Exception innerException);
public ArgumentNullException(string? message, Exception? innerException);
new ArgumentNullException : string * Exception -> ArgumentNullException
Public Sub New (message As String, innerException As Exception)

参数

message
String

说明此异常原因的错误消息。

innerException
Exception

作为当前异常的原因的异常,如果未指定内部异常,则为 null 引用(Nothing 在 Visual Basic 中)。

适用于

ArgumentNullException(String, String)

Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs
Source:
ArgumentNullException.cs

使用指定的错误消息和导致此异常的参数的名称初始化类的实例 ArgumentNullException 。

public:
 ArgumentNullException(System::String ^ paramName, System::String ^ message);
public ArgumentNullException(string paramName, string message);
public ArgumentNullException(string? paramName, string? message);
new ArgumentNullException : string * string -> ArgumentNullException
Public Sub New (paramName As String, message As String)

参数

paramName
String

导致异常的参数的名称。

message
String

描述错误的消息。

注解

此构造函数使用参数的值初始化 Message 新实例的属性 message 。 参数的内容 message 旨在由人类理解。 此构造函数的调用方必须确保此字符串已本地化为当前系统区域性。

此构造函数使用ParamName参数初始化paramName新实例的属性。 paramName 的内容旨在由人类理解。

下表显示了 ArgumentNullException实例的初始属性值。

财产 价值
InnerException Null 引用(Nothing 在 Visual Basic 中)。
Message 错误消息字符串。
ParamName 参数名称字符串。

适用于