Gur*_*epS 2 .net c# visual-studio-2008
当我将字符串传递给异常参数时,Visual Studio似乎抱怨.
if (str1 == null || str2 == null)
{
throw new ArgumentNullException("lmkl");
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio说它无法解析符号"lmkl".
如果我有一个字符串变量(例如上面的throw new... string s = "test";)并将其作为异常的参数包含在内,那么Visual Studio对此非常满意.
是什么赋予了?
谢谢
该重载构造函数的文档ArgumentNullException采用单个字符串参数声明该参数应为:
The name of the parameter that caused the exception.
目前,如果您的代码抛出异常,您将不知道哪个参数为null.
建议改写
if (str1 == null) throw new ArgumentNullException("str1");
if (str2 == null) throw new ArgumentNullException("str2");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
711 次 |
| 最近记录: |