请看下面的代码:
string test = "";
int output = -1;
if (int.TryParse(test, out output))
{
Console.WriteLine("Parsed");
}
Console.WriteLine(output);
当 TryParse()
失败时,不应该跳过该 block ,不调用 Console.WriteLine("Parsed")
并输出 的值
是否相同 (-1)?
返回 0
最佳答案
来自 MSDN :
When this method returns, contains the 32-bit signed integer value equivalent to the number contained in string, if the conversion succeeded, or
zero
if the conversion failed.
关于c# - TryParse() - 为什么此代码返回 0,结果不应该是 -1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11012462/