小编Kru*_*zer的帖子

Int.tryparse在If条件下无法正常工作 - 任何解释?

这是我使用Int32.TryParsewith if条件的代码片段.(控制台应用程序)

Console.WriteLine("Enter the no of the person(value for n)");
string number = Console.ReadLine();            
Console.WriteLine("Enter the no of the bulb whose state you want to check(value for x)");
string bulbNumber = Console.ReadLine();           
if ((Int32.TryParse(number, out n)) || (Int32.TryParse(bulbNumber, out x)))
{
}
Run Code Online (Sandbox Code Playgroud)

如果我们在quickwatch中检查n的值,那么它会正确捕获您输入的值,但如果您检查x的值,则会出乎意料地为0! - 任何想法如何克服这个?我想知道造成这种异常的原因.

c# console if-statement tryparse

1
推荐指数
1
解决办法
1175
查看次数

标签 统计

c# ×1

console ×1

if-statement ×1

tryparse ×1