相关疑难解决方法(0)

为什么Try-Catch需要花括号

只是好奇:为什么C#中的try catch语法(Java也?)为多个语句硬编码?为什么语言不允许:

int i;
string s = DateTime.Now.Seconds % 2 == 1 ? "1" : "not 1";
try
   i = int.Parse(s);
catch
   i = 0;
Run Code Online (Sandbox Code Playgroud)

这个例子只是为了琐碎的目的.我知道有int.TryParse.

c# try-catch

52
推荐指数
4
解决办法
5279
查看次数

标签 统计

c# ×1

try-catch ×1