这是我使用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! - 任何想法如何克服这个?我想知道造成这种异常的原因.