zoukankan      html  css  js  c++  java
  • 异常处理

    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    
    class Program
    {
        static void Main(string[] args)
        {
            Fa().Write();
            Fa().Write();
            Fa().Write();
        }
    
        private static int result = 0;
        static int Fa()
        {
            try
            {
                result++;
    
                return result;
                //throw new Exception("aaaaaaaaa");
            }
            catch (Exception)
            {
                result++;
            }
            finally
            {
                result++;
            }
            return result;
        }
    }
    
    
    
    
    
    
    
    
    
    static class ObjectExt
    {
        public static void Write(this object obj)
        {
            Console.WriteLine(obj);
        }
    
        public static void Write<T>(this IEnumerable<T> obj)
        {
            if (obj is string)
            {
                Console.WriteLine(obj);
                return;
            }
            foreach (var o in obj)
            {
                Console.WriteLine(o);
            }
        }
    }

    2.

    using System;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    
    class Person
    {
        public int Age { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Fa().Age.Write();
            Fa().Age.Write();
            Fa().Age.Write();
        }
    
    
        static Person Fa()
        {
            var p = new Person
            {
                Age = 100
            };
            try
            {
                p.Age++;
                //throw new Exception("");
                return p;
                //throw new Exception("aaaaaaaaa");
            }
            catch (Exception)
            {
                p.Age++;
                return p;
            }
            finally
            {
                p.Age++;
            }
        }
    }
    
    
    
    
    
    
    
    
    
    static class ObjectExt
    {
        public static void Write(this object obj)
        {
            Console.WriteLine(obj);
        }
    
        public static void Write<T>(this IEnumerable<T> obj)
        {
            if (obj is string)
            {
                Console.WriteLine(obj);
                return;
            }
            foreach (var o in obj)
            {
                Console.WriteLine(o);
            }
        }
    }
  • 相关阅读:
    bzoj 1017 魔兽地图DotR
    poj 1322 chocolate
    bzoj 1045 糖果传递
    poj 3067 japan
    timus 1109 Conference(二分图匹配)
    URAL 1205 By the Underground or by Foot?(SPFA)
    URAL 1242 Werewolf(DFS)
    timus 1033 Labyrinth(BFS)
    URAL 1208 Legendary Teams Contest(DFS)
    URAL 1930 Ivan's Car(BFS)
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7686147.html
Copyright © 2011-2022 走看看