码迷,mamicode.com
首页 > 其他好文 > 详细

/异常语句try,catch.

时间:2016-03-11 22:29:02      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

            //try//保护执行里面的代码段,若其中一句错误,直接跳转到catch,不会管下面的内容
            //{
            //    Console.WriteLine("请输入一个整数");
            //    int a = int.Parse(Console.ReadLine());
            //    Console.WriteLine("hello");
            //    break;
            //}
            //catch//
            //{
            //    Console.WriteLine("您的输入有误");
            
            
            //}
            //Console.ReadLine();


           //for与if  else的使用

            Console.WriteLine("你爱不爱我");
            
            for (int i = 1; i <= 3; i++)
            {
                string a = Console.ReadLine();
                if (a == "爱")
                {
                    Console.WriteLine("我也爱你");
                    System.Threading.Thread.Sleep(2000);//单位:毫秒 
                    Console.WriteLine("从此王子和公主过上了没羞没臊的生活");
                    break;
                }
                else
                {
                    if (i == 1)
                    {
                        Console.WriteLine("你爱不爱我");
                    }
                    if(i == 2)
                    {
                        Console.WriteLine("我问你,你到底爱不爱我");
                    }
                    if (i == 3)
                    {
                        Console.WriteLine("滚");
                    }
                    
                }

            }
            Console.ReadLine();



            //请输入年月日,判断格式是不是正确

            //for (; ; )
            //{
            //    Console.WriteLine("请输入年份:");
            //    int y = int.Parse(Console.ReadLine());
            //    if (y >= 0 && y <= 9999)
            //    {
            //        for (; ; )
            //        {
            //            Console.WriteLine("请输入一个月份:");
            //            int m = int.Parse(Console.ReadLine());
            //            if (m > 0 && m <= 12)
            //            {
            //                for (; ; )
            //                {
            //                    Console.WriteLine("请输入一个日期:");
            //                    int d = int.Parse(Console.ReadLine());
            //                    if (d > 0 && d <= 31)
            //                    {
            //                        Console.WriteLine(y+ "年"  + m + "月" + d+ "日" );
            //                        break;
            //                    }
            //                    else
            //                    {
            //                        Console.WriteLine("您输入的日期有误");
            //                    }
            //                }
            //                break;
            //            }
            //            else
            //            {
            //                Console.WriteLine("您输入的月份有误");
            //            }
            //        }
            //        break;
            //    }



            //    else
            //    {
            //        Console.WriteLine("您的输入年份有误");
            //    }
            //}
            //    Console.ReadLine();

 

/异常语句try,catch.

标签:

原文地址:http://www.cnblogs.com/xingfudehuanyan/p/5266413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!