问题描述
我编写的程序设置为只接受正整数作为输入.如果用户输入了一个字母,那么它就会崩溃.负整数不会引起任何问题,尽管就我的程序如何运行而言它不是有效的".
The program I've written is set to only accept positive integers as input. If the user inputs a letter instead, then it crashes. Negative integers don't cause any problems, though it's not 'valid' in regards to how my program functions.
我想做的是:
防止程序因无效输入而崩溃.
Prevent the program from crashing from invalid input.
如果输入无效,则显示错误消息
Display an error message if the input is invalid
让程序从中断处继续,而不影响程序的其余部分.
Have the program continue where it left off, without affecting the rest of the program.
另外,我的程序的一部分涉及除法.有没有办法防止用户输入全零?
Also, a part of my program involves division. Is there a way to prevent the user from entering all zeros?
这是在 C# 中
我的代码:
使用 System.Collections.Generic;使用 System.Linq;使用 System.Text;
using System.Collections.Generic; using System.Linq; using System.Text;
命名空间整体计算器{
}
推荐答案
给你:
这篇关于如何防止由于 C# 中的无效输入而导致崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!