zoukankan      html  css  js  c++  java
  • C#流程控制_异常捕获_try-catch使用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace _02异常捕获
    {
        class Program
         {
            static void Main(string[] args)
              {
                //语法上没有错误,在程序运行的过程当中,由于某些原因程序出现了错误,不能再正常的运行。
                bool b = true;
                int number=0;//声明了一个变量
                Console.WriteLine("请输入一个数字");    
                try
                {
                  //abc
                  number = Convert.ToInt32(Console.ReadLine());//赋值

                }
                  // Console.WriteLine("fdsfdsfds");      
                catch
                 {
                  Console.WriteLine("输入的内容不能够转换成数字");
                  b = false;
                  }
                  //我们如果要执行下面这行代码,需要满足某些条件。
                  //让代码满足某些条件去执行的话,使用bool类型
                if (b)
                  {
                Console.WriteLine(number * 2);//使用
                    }
                Console.ReadKey();
          }
        }
    }

  • 相关阅读:
    PythonのTkinter基本原理
    使用 Word (VBA) 分割长图到多页
    如何使用 Shebang Line (Python 虚拟环境)
    将常用的 VBScript 脚本放到任务栏 (Pin VBScript to Taskbar)
    关于 VBScript 中的 CreateObject
    Windows Scripting Host (WSH) 是什么?
    Component Object Model (COM) 是什么?
    IOS 打开中文 html 文件,显示乱码的问题
    科技发展时间线(Technology Timeline)
    列置换密码
  • 原文地址:https://www.cnblogs.com/momj/p/14262024.html
Copyright © 2011-2022 走看看