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

首頁 > 編程 > C# > 正文

C#中的try catch finally用法分析

2019-10-29 21:47:50
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了C#中的try catch finally用法,以實例形式分析了try catch finally針對錯誤處理時的不同用法,具有一定的參考借鑒價值,需要的朋友可以參考下
 

本文實例講述了C#中的try catch finally用法。分享給大家供大家參考。具體分析如下:

try中的程序塊是有可能發生錯誤的程序塊,catch中的程序塊是當發生錯誤的時候才會執行的代碼塊,finally中的程序塊是無論是否發生錯誤都會執行的代碼塊。

示例程序:

復制代碼代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Sample_01_CA
{
    public class Complex
    {
        static void Main(string[] args)
        {
            int i = 2008;
            int j = 0;
            try
            {
                int result = i / j;
            }
            catch
            {
                Console.WriteLine("J變量的值為0");
            }
            finally
            {
                Console.WriteLine(j.ToString());
            }
            Console.Read();
        }
    };
}

 

程序輸出為:

J變量的值為0

0

示例程序:

復制代碼代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Sample_01_CA
{
    public class Complex
    {
        static void Main(string[] args)
        {
            int i = 2008;
            int j = 2;
            try
            {
                int result = i / j;
            }
            catch
            {
                Console.WriteLine("J變量的值為0");
            }
            finally
            {
                Console.WriteLine(j.ToString());
            }
            Console.Read();
        }
    };
}

 

程序輸出為:

0

希望本文所述對大家的C#程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湟中县| 长宁区| 建德市| 绥芬河市| 略阳县| 东乌珠穆沁旗| 灌阳县| 手游| 岳阳县| 纳雍县| 鲁山县| 米易县| 河源市| 门源| 黑河市| 富川| 朝阳区| 乌苏市| 绥芬河市| 水城县| 玛多县| 西吉县| 噶尔县| 资中县| 共和县| 定边县| 怀宁县| 安平县| 博乐市| 汉寿县| 加查县| 新民市| 乐安县| 阜宁县| 浦城县| 黄梅县| 驻马店市| 双城市| 潞西市| 梓潼县| 抚宁县|