更新时间:2023-11-28 17:29:28
从调试器开始:运行你的应用程序,然后输入你的数据。然后在行上放置一个断点
Start with the debugger: run your app, and enter your data. Then put a breakpoint on the line
ProcessMenuItem(menuItem, contactList);
在你的Main方法中。
输入你的U进行更新,它应该点到断点。
步入方法你会发现自己在这里:
in your Main method.
Enter your "U" to update and it should hit the breakpoint.
Step into the method and you should find yourself here:
switch (menuItem)
检查调试器中menuItem的值 - 它应该仍然是'U'但确保 - 并确保contactList中有项目。
单步执行:交换机应引导您更新联系。
然后,逐步完成该方法,确定在执行一行之前应该发生什么。那发生了吗?如果没有,为什么不呢?
如果发生任何事情,你没想;看看为什么 - 这可能与你的问题有关。
这是一项技能,称为调试,就像所有必须实践的技能一样,才能正确开发它。在这样的小任务中学习它是一个很好的开始方式!
Check the value of menuItem in the debugger - it should still be 'U' but make sure - and make sure there are items in your contactList.
Step through: the switch should lead you to updateContact.
Then, step through the method, working out exactly what should happen before tyou execute a line. Did that happen? If not, why not?
If anything happens that you didn;t expect, look at why - that may be related to your problem.
This is a skill, called debugging and like all skills it has to be practiced to develop it properly. And learning it while working in a small task like this is a good way to start!