zoukankan      html  css  js  c++  java
  • try catch finally 与continue的使用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 子类与父类的相互转换
    {
        class Program
        {
            static void Main(string[] args)
            {
                //try catch finally 与 continue
                //如果在try中遇到continue,则忽略try中continue之后的语句
                //但是依然执行finally中语句
                //finally之外的语句也不执行
                bool _flag = true;
                while(true)
                {
                    try
                    {
                        if(_flag)
                            continue;
                        
                        //如果_falg为true,这下面的两句不执行
                        Person per = new Student();
                        per.Say();//此时输出father
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        //如果try中执行了continue,则这两句依然要执行
                        Console.WriteLine("finally");
                        Console.ReadKey();
                    }
    
                    //如果在try中执行continue,则下面的两条语句并不执行
                    Console.WriteLine();
                    Console.ReadKey();
                }
                
            }
        }
    
        class Person
        {
            public void Say()
            {
                Console.WriteLine("father");
            }
            
        }
    
        class Teacher:Person
        {
            public void Say()
            {
                Console.WriteLine("Teacher");
            }
        }
    
        class Student:Person
        {
            public void Say()
            {
                Console.WriteLine("Student");
            }
        }
         
    }
    

      

  • 相关阅读:
    WPF 策略模式
    老陈 WPF
    老陈 ASP.NET封装
    小石头 封装
    典型用户故事
    整数的四则运算
    对git的认识
    如何学习计算机
    团队编程二——web应用之人事管理系统
    团队编程——web应用之人事管理系统
  • 原文地址:https://www.cnblogs.com/my-cat/p/7610297.html
Copyright © 2011-2022 走看看