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

首頁(yè) > 編程 > C# > 正文

C#中的try catch finally用法分析

2020-01-24 02:13:09
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

try中的程序塊是有可能發(fā)生錯(cuò)誤的程序塊,catch中的程序塊是當(dāng)發(fā)生錯(cuò)誤的時(shí)候才會(huì)執(zhí)行的代碼塊,finally中的程序塊是無(wú)論是否發(fā)生錯(cuò)誤都會(huì)執(zhí)行的代碼塊。

示例程序:

復(fù)制代碼 代碼如下:
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

示例程序:

復(fù)制代碼 代碼如下:
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

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新密市| 镇赉县| 滨海县| 寿阳县| 阿合奇县| 汪清县| 湟中县| 珲春市| 通江县| 仪陇县| 汶川县| 缙云县| 鄂托克前旗| 资溪县| 兴国县| 阿巴嘎旗| 年辖:市辖区| 吴堡县| 偃师市| 墨竹工卡县| 镇原县| 新泰市| 绥阳县| 河东区| 黄石市| 湄潭县| 惠来县| 德安县| 鹤岗市| 河曲县| 长治县| 南和县| 通渭县| 浦江县| 桦南县| 化州市| 化州市| 梁山县| 辽源市| 广宗县| 黄大仙区|