日期:2014-05-17  浏览次数:20424 次

if语句执行不正确
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("您见过老佛爷吗?");
  }

  }
  }
}


------解决方案--------------------
你的与输入别的数据相应的显示语句呢
------解决方案--------------------
探讨

你的与输入别的数据相应的显示语句呢

------解决方案--------------------
应该是在string agedesc = GetAgeDsc(300);这句后面加个输出

 Console.WriteLine(agedesc );