throw 用来抛出异常,可自己编写代码,抛出所需要的异常。
代码如下:
using Systemusing System.Collections.Generic
using System.Linq
using System.Text
namespace CheckedAndUnchecked
{
class Program
{
static void Main(string[] args)
{
int month
string b
Console.WriteLine("请输入月份的值:")
b = Console.ReadLine()
month = int.Parse(b)
switch (month)
{
case 1:
Console.WriteLine("January")
break
case 2:
Console.WriteLine("Feburary")
break
case 3:
Console.WriteLine("March")
break
case 4:
Console.WriteLine("April")
break
case 5:
Console.WriteLine("May")
break
case 6:
Console.WriteLine("June")
break
case 7:
Console.WriteLine("July")
break
case 8:
Console.WriteLine("August")
break
case 9:
Console.WriteLine("September")
break
case 10:
Console.WriteLine("October")
break
case 11:
Console.WriteLine("Novemer")
break
case 12:
Console.WriteLine("December")
break
default:
throw new ArgumentOutOfRangeException("不存在的月份") // throw
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)