namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
string agedesc = GetAgeDsc(300);//这里传入150以上的值,就会出现正常的("您见过老佛爷吗?");,但是输入其它值,却出现一个黑屏,什么提示也不出现,是下面的if语句那个地方写错了呢?
}
catch(Exception ex)
{
Console.WriteLine("数据错误:" + ex.Message);
}
Console.ReadKey();
}
static string GetAgeDsc(int age)
{ if(age > 0 && age <= 3)
{
return ("婴幼儿");
}
else if (age > 3 && age <= 18)
{
return ("青少年");
}
else if (age > 19 && age < 150)
{
return ("成年人");
} if (age < 0)
{
throw new Exception("您来自反物质世界吧?");
} else
{
throw new Exception("您见过老佛爷吗?");
} }
}
}
{
class Program
{
static void Main(string[] args)
{
try
{
string agedesc = GetAgeDsc(300);//这里传入150以上的值,就会出现正常的("您见过老佛爷吗?");,但是输入其它值,却出现一个黑屏,什么提示也不出现,是下面的if语句那个地方写错了呢?
}
catch(Exception ex)
{
Console.WriteLine("数据错误:" + ex.Message);
}
Console.ReadKey();
}
static string GetAgeDsc(int age)
{ if(age > 0 && age <= 3)
{
return ("婴幼儿");
}
else if (age > 3 && age <= 18)
{
return ("青少年");
}
else if (age > 19 && age < 150)
{
return ("成年人");
} if (age < 0)
{
throw new Exception("您来自反物质世界吧?");
} else
{
throw new Exception("您见过老佛爷吗?");
} }
}
}
解决方案 »
- 关于B/S架构
- 学习验证控件遇到n多问题 大哥们进来看看
- 给定一个任意四边形,求其内包含多少网格?
- javascrip脚本在.net中的设置模板页的内容页中怎么写?
- NET 生成文件夹
- 帅哥们,我来求正则表达式 。C:\web\web.eghotel.com\1\tt.html..如何截取出网址 web.eghotel.com\1\tt.html
- 紧急!Windows Forms Controls 如何嵌入到IE中?
- sharepoint
- 类型初始值设定项引发异常----小白,我要疯了啊
- asp.net中的smtpmail类怎么用?
- mvc3求解:ajax上传文件返回json数据,结果提示“下载保存”
- Asp.net 获取客户端windows登录用户名的问题
把你的return改成Console.WriteLine吧
对,没有显示
string agedesc = GetAgeDsc(300);
Console.WriteLine(agedesc);
{
return ("婴幼儿");
}
if (age > 3 && age <= 18)
{
return ("青少年");
}
if (age > 19 && age < 150)
{
return ("成年人");
}
可是为什么传入300的时候可以显示呢,而不用Console.WriteLine(agedesc);语句
但是其它却要这个语句?
是的,300抛出异常,并且异常被显示了:
catch(Exception ex)
{
Console.WriteLine("数据错误:" + ex.Message);
}
Console.ReadKey();
}