且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有人可以解释一下这段代码。

更新时间:2023-11-09 22:47:16

感谢大家的回复。我发现所有解决方案都很有用。一旦我完成了C#的基础知识,我肯定会从更高级的主题开始,比如调试器和理解VStudios更好地开发基于窗口的应用程序而不是基于控制台。



再次感谢。
Thanks everyone for your replies. I found all the solutions useful. Once I complete the basics of C# I will definitely start with more advanced topics such as debugger and understanding VStudios better for developing window based apps rather than console based.

Thanks again.


理解代码的更好方法可能是调试它。使用调试器逐行完成代码。调查变量,查看影响执行的因素等。掌握调试器是开发人员的关键技能之一。



对于初学者,请查看调试器入门 - Visual Studio | Microsoft Docs [ ^ ]
Probably a better way to understand the code would be to debug it. Use the debugger to go through the code line-by-line. Investigate the variables, see what affects the execution and so on. Mastering the debugger is one of the key skills for a developer.

For starters, have a look at Get started with the debugger - Visual Studio | Microsoft Docs[^]


无论您是否拥有有效号码,您的循环计数器( i )都在前进。考虑更改; i ++);)并添加 i ++; 关注 sum + =已解析;



假设你这样做,在输入所请求的有效整数数之前,您永远不会退出循环。因此,最后检查 parseTry 是不必要的。实际上,通过这些更改,您可以使 parse尝试循环的局部变量。
Your loop counter (i) is advancing regardless of whether you have a valid number or not. Consider changing "; i++)" to "; )" and adding an "i++;" following "sum += parsed;".

Assuming you do this, you will never exit the loop until you have entered the requested number of valid integers. Thus, the final check of parseTry is unnecessary. In fact, with those changes, you can make parseTry a variable local to the loop.