相关疑难解决方法(0)

C#"最终"阻止总是执行吗?

可能重复:
如果我在Try块中返回一个值,是否会触发Finally语句中的代码?

请考虑以下代码C#代码."finally"块是否执行?

public void DoesThisExecute() {
   string ext = "xlsx";
   string message = string.Empty;
   try {
      switch (ext) {
         case "xls": message = "Great choice!"; break;
         case "csv": message = "Better choice!"; break;
         case "exe": message = "Do not try to break me!"; break;
         default:
            message = "You will not win!";
            return;
      }
   }
   catch (Exception) {
      // Handle an exception.
   }
   finally {
      MessageBox.Show(message);
   }
}
Run Code Online (Sandbox Code Playgroud)

哈,在我写完这篇文章之后,我意识到我本可以在Visual Studio中自己测试过.但是,请随时回答!

c# try-catch

68
推荐指数
5
解决办法
8万
查看次数

标签 统计

c# ×1

try-catch ×1