gpt4 book ai didi

c# - TryParse() - 为什么此代码返回 0,结果不应该是 -1?

转载 作者:太空狗 更新时间:2023-10-29 18:02:43 26 4
gpt4 key购买 nike

请看下面的代码:

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/

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