新郑市剑桥小学官网:WinForm中的字符串转换

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 15:59:40
using System;

namespace ConsoleApplication1
{
public class TestException:Exception
{
public TestException():base(){}
public TestException(string message):base(message){}
public TestException(string message,Exception innerException):base(message,innerException){}
}
class ExceptionTestApp
{
static void Main(string[] args)
{
try
{
int i;
Console.WriteLine("请输入一个字符");
i=Convert.ToInt32(Console.ReadLine());
if(i>10)
{
Console.WriteLine("OK!");
}
else if(i>5)
{
throw new TestException("Err Input!");
}
}
catch(Exception e)
{
TestException Ex=new TestException("Catch!",e);
Console.WriteLine(Ex.Message);
}
Console.ReadLine();
}
}
}
当这段控制台程序运后,输入字母"A"时,程序的运行结果应当为().
A)OK!
B)Err Input!
C)Catch!
D)无显示

这道题我选的是C,当向程序输入字母"A"时,A将被视为一个字符串,将字符串A转换成INT类型的数据会出现异常,所以我选C.如果输入的不是字符"A"而是数字"65",那么这段程序的输出应当是"OK!",这时才会选A.
跟同学对答案的时候大部选A,各位是怎么看的.