• 异常处理


    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);
            }
        }
    }
  • 相关阅读:
    质因数分解
    P1939 【模板】矩阵加速(数列)
    UVALive
    Python操作MySQL:pymysql模块
    Mysql数据库基础
    Redis管道和发布订阅
    Redis常用操作
    Redis操作集合,有序集合
    Redis操作list
    Redis操作hash
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7686147.html
Copyright © 2020-2023  润新知