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

标签 c# .net console tryparse

请看下面的代码:

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/

相关文章:

c# - 将注册表写入 hkey_current_user 而不是 hkey_users

c# - 基于 XAML 的关卡编辑器

c# - 在 C# 中从 url(仅第一个根目录值)获取第一部分

python - 将控制台输入行保持在输出下方

c++ - MFC : Fix a console on a GUI

c# - 从 Azure 下载文件的 Web 服务会引发大文件异常

c# - 如何在 C# 中执行 VBScript

c# - 如何通过属性控制方法行为?

c# - 你如何实现可链接的异步扩展方法?

java - 如何在控制台上显示字符串?