国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#異常處理示例分享

2020-01-24 02:43:57
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
//2014.3.14
namespace _6.異常
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Convert之前");
                int a = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Convert之后");
            }
            catch (Exception ex)
            {
                Console.WriteLine("輸入錯誤:"+ex.Message+"異常堆棧:"+ex.StackTrace);
            }

            try
            {
                Console.WriteLine("請輸入你的年齡:");
                int s = Convert.ToInt32(Console.ReadLine());
                string desc = GetAgeDesc(s);
                Console.WriteLine(desc);
            }
            catch (Exception ex)
            {
                Console.WriteLine("數據錯誤,"+ex.Message);
            }
             Console.ReadKey();
        }

        static string GetAgeDesc(int age)
        {
            if (age >= 0 && age <= 3)
            {
                return "嬰幼兒";
            }
            else if (age > 3 && age < 18)
            {
                return "青少年";
            }
            else if (age >=18 && age < 60)
            {
                return "成年人";
            }
            else if (age >= 60 && age < 100)
            {
                return "老年人";
            }
            else
            {
                throw new Exception("自己創建的ex.Message");
            }
        }
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵南县| 铁岭市| 始兴县| 鹿泉市| 三台县| 马山县| 宁德市| 平泉县| 池州市| 渝中区| 垣曲县| 商水县| 平昌县| 临潭县| 东乡| 万源市| 景泰县| 无极县| 静乐县| 临夏县| 西林县| 旌德县| 新密市| 清苑县| 西昌市| 晋宁县| 贵溪市| 武功县| 青冈县| 洞口县| 共和县| 公主岭市| 丁青县| 黔西县| 马关县| 镇远县| 集安市| 榆中县| 军事| 金寨县| 玉溪市|