小编典典

C#“最终”块是否总是执行?

c#

考虑以下代码C#代码。是否执行“最终”块?

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);
   }
}

哈,写完这些之后,我意识到自己可以在Visual Studio中自己测试一下。但是,请随时回答!


阅读 312

收藏
2020-05-19

共1个答案

小编典典

是的,它确实是:-) http://msdn.microsoft.com/zh-
cn/library/zwc8s4fz.aspx

2020-05-19