gpt4 book ai didi

c# - 无法在异常构造函数中写入字符串

转载 作者:行者123 更新时间:2023-11-30 19:01:00 26 4
gpt4 key购买 nike

当我将字符串传递给异常参数时,Visual Studio 似乎会报错。

if (str1 == null || str2 == null)
{
throw new ArgumentNullException("lmkl");
}

Visual Studio 表示它无法解析符号 "lmkl"

如果我有一个字符串变量(例如上面的 throw new...string s = "test";)并将其作为异常的参数,Visual Studio 对此非常满意.

什么给了?

谢谢

最佳答案

采用单个字符串参数的 ArgumentNullException 的重载构造函数的文档指出该参数应为:

The name of the parameter that caused the exception.

At the moment, if your code throws an exception you won't know which argument was null.

Recommend rewriting to

if (str1 == null) throw new ArgumentNullException("str1");
if (str2 == null) throw new ArgumentNullException("str2");

关于c# - 无法在异常构造函数中写入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/553762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com