| 黄宁川 发表于 2012-5-1 22:17 ![]() 如果去掉int a , int b 的话就出现第一张图的问题,我再发下去掉后出现问题的包含错误列表的截图 ...
不好意思,最近几天没上论坛,刚看到,也把你这个问题简单做了一遍,代码如下:
 namespace 输入最大数与最小数之间的数
 {
 class Program
 {
 static void Main(string[] args)
 {
 Console.WriteLine("请输入一个数字!");
 int i = 0;
 i = readInt(2, 10);
 Console.ForegroundColor = ConsoleColor.Blue;// 蓝色
 Console.WriteLine("您输入了数字"+ i);
 Console.ReadKey();
 }
 public static int readInt()
 {
 int i = readInt(int.MaxValue, int.MinValue);
 return i;
 }
 public static int readInt(int min, int max)
 {
 while (true)
 {
 try
 {
 int number = Convert.ToInt32(Console.ReadLine());
 if (number < min || number > max)
 {
 Console.WriteLine("只能输入{0}-{1}之间的数字,请重新输入!", min, max);
 continue;
 }
 return number;
 }
 catch
 {
 Console.WriteLine("只能输入数字,请重新输入!");
 }
 }
 }
 }
 }
 你最后运行时你看看传参数了没。比如: i = readInt(2, 10);
 
 |